Anda di halaman 1dari 33

UNI-PIC-SDK

USER MANUAL
TABLE OF CONTENTS

PAGE
1. TECHNICAL FEATURES....................... 3

2. LIST OF SUPPORTED ICS.................... 4

3. CIRCUIT DIAGRAM & DESCRIPTION............ 5

4. PROGRAMMING USING PICFlash-ISP........... 9

5. PROGRAMMING USING ICD-2.................. 11

6. SAMPLE PROGRAMS
1. DANCING LIGHTS....................... 13
2. ADC DEMO............................. 15
3. REAL TIME CLOCK...................... 17
4. COUNTER USING 7-SEGMENT DISPLAY...... 19
5. MATRIX KEYBOARD...................... 23
6. I2C EEPROM........................... 25
7. SERIAL PORT.......................... 27
8. LCD.................................. 28
9. RELAY................................ 29
10. RC5 REMOTE CONTROL................... 31

UNI-PIC-SDK
1. Technical Features

1. TECHNICAL FEATURES

¾ Experimental board for 40/28/18-pin PIC family of microcontrollers


¾ ICSP facility using PICFLash-ISP/ICD-2
¾ On-board RS232 Compatible Serial Interface terminated in a 9-Pin 'D'
female connector
¾ 4 x 4 Matrix Keyboard
¾ Two 16x2 Alphanumeric LCD connector (4-bit interface) and trimmer for
contrast adjustment
¾ Four 7-Segment LED Displays
¾ I2C EEPROM (24Cxx)
¾ Real Time Clock (DS1307) with Lithium battery and SRAM
¾ 8-High current output port (500mA) for driving external loads
¾ One 12V Relay
¾ Buzzer
¾ Temperature sensor with thermostat functions (DS1821) [Optional]

UNI-PIC-SDK
2. Supported ICs

2. SUPPORTED ICs

1. PIC16F627
2. PIC16F627A
3. PIC16F628
4. PIC16F628A
5. PIC16F648
6. PIC16F648A
7. PIC16F72
8. PIC16F73
9. PIC16F84
10. PIC16F84A
11. PIC16F870
12. PIC16F872
13. PIC16F873
14. PIC16F873
15. PIC16F874
16. PIC16F876
17. PIC16F876A
18. PIC16F877
19. PIC16F877A
20. PIC18F242
21. PIC18F252
22. PIC18F442
23. PIC18F452

UNI-PIC-SDK
3. Circuit Diagram

UNI-51-SDK
3. Circuit Diagram

UNI-PIC-SDK
3. Circuit Diagram

UNI-PIC-SDK
3. Circuit Diagram

UNI-PIC-SDK
4. Programming using PICFlash-ISP

4. PROGRAMMING USING PICFlash-ISP

Before proceeding, make sure that you have connected the


PICFlash-ISP to computer using 9-pin serial cable and UNI-PIC-SDK board is
connected to PICFlash-ISP using 10-pin ribbon cable and power is turned on.

Step 1: Install PICFlash-ISP software from CD.

Step 2: Run it from Start->Programs->PICFlash-ISP. The main window of the


software will appear as shown below.

Fig. 4.1: PICFlash-ISP Main Window

UNI-PIC-SDK
4. Programming using PICFlash-ISP

Step 3: Open the hex file of your program using “Open” button.

Step 4: Click “Program” button on main window and wait for the programming to
complete.

UNI-PIC-SDK
5. Programming using ICD-2

5. PROGRAMMING USING ICD-2


Before proceeding, make sure that you have connected the ICD-2
to computer using either USB or 9-pin serial cable and UNI-PIC-SDK board is
connected to ICD-2 using 6-pin RJ45 cable and power is turned on.

Step 1: Install MPLAB IDE software from CD. Skip this step if it is already
installed.

Step 2: Run it from Start->Programs->Microchip->MPLAB IDE. The main window


of the software will appear as shown below.

UNI-PIC-SDK
5. Programming using ICD-2

Step 3: From the Programmer menu select programmer as MPLAB ICD2.

Step 4: Click File->Import menu, browse and open your program’s HEX File.

Step 5: Click Programmer->Program menu to begin programming.

Step 6: To run your program, click Programmer->Release from Reset

You need to repeat steps 4 – 6 every time you change your program.

UNI-PIC-SDK
6. Sample Programs

SAMPLE PROGRAMS

//********************************************************************
// DANCING LIGHTS
//********************************************************************
// 1) TURN-ON ALL SWITCHES ON SW5 (FOR PORT LED's)
// 2) MAKE SURE NO JUMPERS ARE CONNECTED ANYWHERE ON THE BOARD
// 3) NO LCD SHOULD BE CONNECTED
// 4) 7-SEGMENT DISPLAYS SHOULD BE TURNED OFF
// 5) REMOVE ICD2/PICFLASH CABLE AFTER PROGRAMMING
//********************************************************************

#include "DancingLights.h"

void main(void)
{
unsigned char i,j,k;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!


while(1)
{
i = 0x01;
j = 0x80;

UNI-PIC-SDK
6. Sample Programs

for(k=0; k<8; k++)


{
output_a(~i);
output_b(~j);
output_c(~i);
output_d(~j);
output_e(~i >> 6);

i <<= 1;
j >>= 1;
delay_ms(100);
}
}
}

UNI-PIC-SDK
6. Sample Programs

//*********************************************************************
// ADC DEMO:
// THIS PROGRAM DISPLAYS ADC CH.2 and CH.3 VALUES ON LCD
//*********************************************************************
// 1) LCD IS CONNECTED ON PORT-D
// 2) CONNECT JP13 AND JP14 FOR ANALOG INPUTS TO PORT-A
// 3) MAKE SURE NO JUMPERS ARE CONNECTED ANYWHERE ON THE BOARD
// 4) ALL PORT-A PULL-UP SWITCHES (SW1) SHOULD BE TURNED OFF
// 5) 7-SEGMENT DISPLAYS SHOULD BE TURNED OFF (SW2)
// 6) VARY VR2 AND VR3 TO CHANGE ANALOG INPUT TO ADC
//*********************************************************************

#include "ADC.h"
#include "LCD_Driver.c"

void main(void)
{
long ra2, ra3;

setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!


lcd_init();
lcd_putc("\f ADC Demo");
delay_ms(1000);

while(1)
{
set_adc_channel(2);

UNI-PIC-SDK
6. Sample Programs

delay_us(10);
ra2 = Read_ADC();

set_adc_channel(3);
delay_us(10);
ra3 = Read_ADC();

printf(lcd_putc, "\fRA2=%Lu\nRA3=%Lu", ra2, ra3);


delay_ms(100);
};
}

UNI-PIC-SDK
6. Sample Programs

//*********************************************************************
// REAL-TIME CLOCK DEMO
//*********************************************************************
// 1) USE PULL-UP ON PORT-C
// 2) LCD IS CONNECTED ON PORT-D
// 3) MAKE SURE NO OTHER JUMPERS ARE CONNECTED
// 4) ALL LED's SHOULD BE TURNED OFF (SW5)
// 5) ALL 7-SEGMENT DISPLAYS SHOULD BE TURNED OFF (SW2)
//*********************************************************************

#include "RTC.h"
#include "LCD_Driver.c"
#include "DS1307.c"

#define DS1307_WRITE_ADDRESS 0xD0


#define DS1307_READ_ADDRESS 0xD1

unsigned char second;


unsigned char minute;
unsigned char hour;
unsigned char day;
unsigned char month;
unsigned char year;
unsigned char day_of_week;

void main(void)
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED, 0, 1);

setup_comparator(NC_NC_NC_NC);

UNI-PIC-SDK
6. Sample Programs

setup_vref(FALSE);

// TODO: USER CODE!!


lcd_init();
lcd_putc("\f RTC DEMO\n");
delay_ms(1000);

ds1307_init();

// Set date -> 05 July 2006 Wednesday (3rd day of week)


// Set time -> 18:20:45
ds1307_set_date_time(05, 07, 06, 3, 18, 20, 45);

while(1)
{
ds1307_get_date(day, month, year, day_of_week);
ds1307_get_time(hour, minute, second);

printf(lcd_putc, "\fDate: \%02d/\%02d/\%02d\n", day, month,


year);
printf(lcd_putc, "Time: \%02d:\%02d:\%02d", hour, minute,
second);
delay_ms(1000);
}
}

UNI-PIC-SDK
6. Sample Programs

//*********************************************************************
// 7-SEGMENT COUNTER EXAMPLE
//*********************************************************************
// 1) TURN ON ALL 7-SEGMENT DISPLAYS USING SW2
// 2) USE PULL-UP ON PORT-C
// 3) USE PULL-DOWN (GND) ON SWITCHES (JP15)
// 4) MAKE SURE NO OTHER JUMPERS ARE CONNECTED
// 5) ALL LED's SHOULD BE TURNED OFF (SW5)
// 6) AFTER PROGRAMMING PRESS SWITCH ON PIN RC0 TO INCREMENT COUNT OR
SWITCH ON
// RC1 TO DECREMENT THE COUNT
//*********************************************************************

#include "7-Segment.h"

#define NO_OF_DISPLAYS 4
#define DIS1 PIN_A0
#define DIS2 PIN_A1
#define DIS3 PIN_A2
#define DIS4 PIN_A3
#define SW_UP PIN_C0
#define SW_DN PIN_C1

// Look-up table for display


int8 const table[10]=
{0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

int8 disp_buffer[NO_OF_DISPLAYS];
int8 index;
unsigned int16 count;

// This function is called every time the RTCC (timer0) overflows (255-
>0).
// For this program this is nearly 488 times a second
// 4MHZ/(4*8*256) = ~488
#int_rtcc

UNI-PIC-SDK
6. Sample Programs

void display_isr(void)
{
if(++index > NO_OF_DISPLAYS-1) index=0;

output_b(0x00);
output_low(DIS1);
output_low(DIS2);
output_low(DIS3);
output_low(DIS4);

switch(index)
{
case 0:
output_high(DIS1);
break;
case 1:
output_high(DIS2);
break;
case 2:
output_high(DIS3);
break;
case 3:
output_high(DIS4);
break;
}

output_b(disp_buffer[index]);
}

void update_display_buffer(void)
{
char i, buffer[5];
sprintf(buffer,"%4ld",count);
for(i=0; i<5; i++)
if(buffer[i] < 48 || buffer[i] > 57) buffer[i] = 48;

for(i=0; i<NO_OF_DISPLAYS; i++)

UNI-PIC-SDK
6. Sample Programs

disp_buffer[i] = table[buffer[(NO_OF_DISPLAYS-1)-i] - 48];


}

void main(void)
{
int8 i, temp;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_8 | RTCC_8_BIT);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);

index = 0;
count = 0;
temp = table[0];
for(i=0;i<NO_OF_DISPLAYS; i++)
disp_buffer[i] = temp;

while(1)
{
if(!input(SW_UP))
{
delay_ms(25);
if(!input(SW_UP))
{
if(++count>9999) count=0;
update_display_buffer();
}

UNI-PIC-SDK
6. Sample Programs

}
else if(!input(SW_DN))
{
delay_ms(25);
if(!input(SW_DN))
{
if(--count==0xFFFF)count=9999;
update_display_buffer();
}
}
delay_ms(75);
}
}

UNI-PIC-SDK
6. Sample Programs

//*********************************************************************
// MATRIX KEYBOARD TEST PROGRAM
//*********************************************************************
// 1) CONNECT LCD ON PORT-B
// 2) CONNECT MATRIX KEYBOARD ON PORT-D
// 3) USE PULL-UP ON PORT-D
// 4) MAKE SURE NO OTHER JUMPERS ARE CONNECTED
// 5) ALL LED'S SHOULD BE TURNED OFF (SW5)
// 6) 7-SEGMENT DISPLAYS SHOULD BE TURNED OFF (SW2)
// 7) REMOVE ICD-2/PICFLASH CABLE AFTER PROGRAMMING
// 8) PRESS RESET ONCE TO START THE PROGRAM
//*********************************************************************

#include "Keyboard.h"
#include "LCD_Driver.c"
#include "KBD_Driver.c"

void main(void)
{
char k, count=0;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!

lcd_init();
kbd_init();

UNI-PIC-SDK
6. Sample Programs

lcd_putc("\fMATRIX KEYBOARD\nYOU PRESSED: ");


while (TRUE)
{
k=kbd_getc();
if(k!=0)
{
lcd_gotoxy(14, 2);
lcd_putc(k);
}
}
}

UNI-PIC-SDK
6. Sample Programs

//*********************************************************************
// I2C EEPROM TEST PROGRAM
// THIS PROGRAM READS/WRITES TO I2C EEPROM THROUGH SERIAL-PORT
INTERFACE.
//*********************************************************************
// 1) CONNECT SERIAL PORT JUMPERS JP5 TO RC7 AND JP6 TO RC6
// 2) MAKE SURE LED SWITCHES ARE TURNED OFF (SW5)
// 3) MAKE SURE 7-SEGMENT DISPLAYS ARE TURNED OFF (SW2)
// 4) CONNECT PULL-UP ON PORT-C
// 5) VIEW OUTPUT ON SERIAL TERMINAL AT 9600 BAUD, PARITY=NONE, DATA
BITS = 8,
// STOP BITS=1 (HYPERTERMINAL/TERATERM/REALTERM)
//*********************************************************************
#include "EEPROM.h"
#include "EE2402.c"
#include <input.c>

void main(void)
{
unsigned char value, cmd;
EEPROM_ADDRESS address;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!


init_ext_eeprom();

printf("I2C EEPROM TEST\n\n\r");

UNI-PIC-SDK
6. Sample Programs

do
{
do
{
printf("\r\nRead or Write: ");
cmd=getc();
cmd=toupper(cmd);
putc(cmd);
}while ( (cmd!='R') && (cmd!='W') );

printf("\n\rLocation: ");

#if sizeof(EEPROM_ADDRESS)==1
address = gethex();
#else
#if EEPROM_SIZE>0xfff
address = gethex();
#else
address = gethex1();
#endif
address = (address<<8)+gethex();
#endif

if(cmd=='R')
printf("\r\nValue: %X\r\n",READ_EXT_EEPROM( address ) );

if(cmd=='W')
{
printf("\r\nNew value: ");
value = gethex();
printf("\n\r");
WRITE_EXT_EEPROM( address, value );
}

} while (TRUE);
}

UNI-PIC-SDK
6. Sample Programs

//*********************************************************************
// SERIAL PORT TEST PROGRAM
//*********************************************************************
// 1) CONNECT SERIAL PORT JUMPERS JP5 TO RC7 AND JP6 TO RC6
// 1) MAKE SURE NO OTHER JUMPERS ARE CONNECTED
// 5) ALL LED's SHOULD BE TURNED OFF (SW5)
// 6) ALL 7-SEGMENT DISPLAYS SHOULD BE TURNED OFF (SW2)
// 5) VIEW OUTPUT ON SERIAL TERMINAL AT 9600 BAUD, PARITY=NONE, DATA
BITS = 8,
// STOP BITS=1 (HYPERTERMINAL/TERATERM/REALTERM)
// ANY KEY PRESSED WILL BE ECHOED-BACK
//*********************************************************************
#include "Serial.h"
#include <stdio.h>

void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!


printf("Serial Demo.\n\n\r");
while(1)
{
putchar(getchar());
};
}

UNI-PIC-SDK
6. Sample Programs

//*********************************************************************
// LCD TEST PROGRAM
//*********************************************************************
// 1) CONNECT LCD ON PORT-D
// 2) MAKE SURE NO JUMPERS ARE CONNECTED
// 3) LED's SHOULD BE TURNED OFF (SW5)
// 4) 7-SEGMENT DISPLAYS SHOULD BE TURNED OFF (SW2)
//*********************************************************************

#include "LCD.h"
#include "LCD_Driver.c"

void main(void)
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!


lcd_init();

printf(lcd_putc," UNI-PIC-SDK\nUC Micro Systems");

while(1);
}

UNI-PIC-SDK
6. Sample Programs

//*********************************************************************
// RELAY TEST PROGRAM
//*********************************************************************
// 1) CONNECT JP18 TO RC1 SIDE
// 2) CONNECT JP15 TO PULL-DOWN (PD) SIDE
// 3) CONNECT PULL-UP ON PORT-B
// 4) MAKE SURE NO OTHER JUMPERS ARE CONNECTED
// 5) ALL LED's SHOULD BE TURNED OFF (SW5)
// 6) ALL 7-SEGMENT DISPLAYS SHOULD BE TURNED OFF (SW2)
// 7) LCD SHOULD NOT BE CONNECTED
// 8) ICD-2/PICFLASH CABLE NEEDS TO BE DISCONNECTED AFTER PROGRAMMING
//*********************************************************************
#include "Relay.h"

#define RELAY PIN_C1

void main(void)
{
int1 toggle;
int8 keys;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!


while(1)
{
keys = input_b();
if(keys != 0xFF)

UNI-PIC-SDK
6. Sample Programs

{
delay_ms(50); // Key debounce delay

// Toggle bit on every key press


if(keys == input_b()) toggle = ~toggle;

if(toggle)
output_high(RELAY);
else
output_low(RELAY);

while(input_b() != 0xFF); //Wait for key to be


released
}
}
}

UNI-PIC-SDK
6. Sample Programs

//*********************************************************************
// RC5 REMOTE CONTROL TEST PROGRAM
//*********************************************************************
// 1) CONNECT INFRARED RECEIVER IN ITS SOCKET
// 2) CONNECT JP11 TO RB0 SIDE
// 3) USE PULL-UP ON PORT-B
// 4) CONNECT JP5 TO RC7 AND JP6 TO RC6 FOR SERIAL PORT
// 5) TURN-ON RC1 SWITCH ON SW4
// 6) CONNECT JP18 TO RC1 SIDE FOR RELAY
// 7) MAKE SURE NO OTHER JUMPERS ARE CONNECTED
// 8) ALL LED's SHOULD BE TURNED OFF (SW5)
// 9) 7-SEGMENT DISPLAYS SHOULD BE TURNED OFF (SW2)
// 10) NO LCD SHOULD BE PRESENT IN LCD CONNECTOR
// 11) AFTER PROGRAMMING, PRESSING '1' ON REMOTE WILL TOGGLE THE RELAY
AND
// SIMULTANEOUSLY RC5 CODE AND COMMAND WILL BE SEND TO SERIAL PORT
WHICH CAN
// BE SEEN ON TERMINAL PROGRAM AT 9600 BAUD, DATA BITS=8, STOP
BITS=1
// AND PARITY=NONE
//*********************************************************************

#include "RC5-Remote.h"
#include <stdio.h>

#define IR_PIN PIN_B0


#define RELAY PIN_C1
#define REMOTE_ADDRESS 19

unsigned int16 code;


unsigned int8 address, command;
int1 valid_code, toggle_bit;

#INT_EXT
void RB0_INT(void)
{

UNI-PIC-SDK
6. Sample Programs

unsigned char i;

// If previously received data is pending to be processed, return


back
if(valid_code) return;

delay_us(700); // Go to the centre of first half bit


code = 0; // Initialize code variable
valid_code = 0; // Initialize variable

// Extract all 14-bits spaced at 1.6mS apart


for(i=0; i<14; i++)
{
code <<= 1;
if(!input(IR_PIN)) code |= 1;
delay_us(1600);
}

// Check if both start-bits are '1'


if((code & 0x3000) == 0x3000) valid_code = 1;
}

void main(void)
{
unsigned char address, command;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
port_b_pullups(TRUE);

UNI-PIC-SDK
6. Sample Programs

// TODO: USER CODE!!


enable_interrupts(INT_EXT);
ext_int_edge(H_TO_L);
enable_interrupts(GLOBAL);

printf("RC5 Decoder\n\r");

while(1)
{
if(valid_code)
{
toggle_bit = 0;
if(code & 0x0800) toggle_bit = 1;
// Extract toggle bit
address = (unsigned char)((code >> 6) & 0x1F); //
Extract address
command = (unsigned char)code & 0x3F; //
Extract command

if(address == REMOTE_ADDRESS) // If data is from


valid remote...
{
printf("code=%4LX, command=%2X\n\r", code, command);

// Toggle relay if command is '1'


if(command == 1)
{
if(toggle_bit)
output_high(RELAY);
else
output_low(RELAY);
}
}
valid_code = 0;
}
}
}

UNI-PIC-SDK

Anda mungkin juga menyukai