Procedure to Operate PIC

10
PIC microcontroller PIC16F877A Open MP LAB suite Go to project then next Select PIC16F877A Select CCS compiler for PIC in active toolsuite Pick CCS compiler exe(Ccsc) in location by browsing D:\ Program Files\PICC\Ccsc.exe Create a new project in a new folder by browsing through location. Save the project with a file name in that folder like D:\Program Files\PICC\test\test Go to next and next and finish. Go to file and create new. Type the program and save it with file name extension .c like RTC.c Add that c file in source file. Go to project. Compile. if the program is right, then it is build succeeded and hex file is generated with the same file name of the c file. Open PIC ISP software. Select the generated hex file by browsing. Keep the switches appropriately with power ON and serial cabled with PC. (Switch SW6 should be in upward direction. (i.e) programming mode. Switch SW7 should be upward for on- board experiments like buzzer, RTC. Switch SW7 should be downward for external peripheral interfacing experiments like Model train.) Download the program, and after successful downloading Switch SW6 should be changed to downward direction. (i.e) execution mode. And reset should be pressed.)

Transcript of Procedure to Operate PIC

Page 1: Procedure to Operate PIC

PIC microcontroller PIC16F877A

Open MP LAB suite Go to project then next Select PIC16F877A Select CCS compiler for PIC in active toolsuite Pick CCS compiler exe(Ccsc) in location by browsing D:\Program Files\

PICC\Ccsc.exe Create a new project in a new folder by browsing through location.

Save the project with a file name in that folder like D:\Program Files\PICC\test\test

Go to next and next and finish. Go to file and create new. Type the program and save it with file name

extension .c like RTC.c Add that c file in source file. Go to project. Compile. if the program is right, then it is build

succeeded and hex file is generated with the same file name of the c file.

Open PIC ISP software. Select the generated hex file by browsing. Keep the switches appropriately with power ON and serial cabled with

PC. (Switch SW6 should be in upward direction. (i.e) programming mode. Switch SW7 should be upward for on-board experiments like buzzer, RTC. Switch SW7 should be downward for external peripheral interfacing experiments like Model train.)

Download the program, and after successful downloading Switch SW6 should be changed to downward direction. (i.e) execution mode. And reset should be pressed.)

Page 2: Procedure to Operate PIC

During program downloadingSwitch SW6 should be in upward direction. (i.e) programming mode.

During program executionSwitch SW6 should be in downward direction. (i.e) execution mode. And reset should be pressed.

Switch SW7 should be upward for on-board experiments like buzzer, RTC.

Switch SW7 should be downward for external peripheral interfacing experiments like Model train.

In VPUT-01 Universal PIC Embedded trainer, Two switches are provided. One switch is for programming and Execuation(PIC ,dsPIC and 89C51 microcontrollers). If the Switch is in Porg. mode, CPU goes to Boot mode.In boot mode we can download the Hex files through windows serial downloader(e.g PIC ISP,Win ISP). If Switch is in Exec mode CPU goes to Execuation mode.User code going to be executed. Another one switch for selection of Internal and external peripherals. If the switch is in Internal mode,we can access the onboard peripherals. It the switch is in the External

Page 3: Procedure to Operate PIC

mode we can access the add-on cards without distrubing the onboard peripherals.

Real Time clock

//This Program for Serial Real time Clock

//display clock time in 7-segment display

//set alarm time and buzzer on alarm time for 5 sec

//SCL - RC3

//SDA - RC4

//DEVICE ADDRESS - 0XA0 - 0XA1

#include <16F877.H>

#use delay(clock=20000000)

#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)

#use I2C(MASTER,sda=PIN_C4,scl=PIN_C3)

unsigned int time[]={0x05,0x57}; //(seconds,minute)

unsigned int readtime[0x02];

unsigned long int second,second1,minute,minute1;

unsigned int a,b,a1,b1,c1,d1,dat;

int i,j;

unsigned char array[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};

void set_rtc_time()

{

for (i=2;i<=3;i++)

{

i2c_start();

i2c_write(0xa0 | 0x00);

i2c_write(i);

Page 4: Procedure to Operate PIC

i2c_write(time[(i-2)]);

i2c_stop();

}

}

void get_rtc_time()

{

for (i=2;i<=3;i++)

{

delay_ms(5);

i2c_start();

i2c_write(0xa0);

i2c_write(i);

i2c_start();

i2c_write(0xa0 | 0x01);

readtime[(i-2)]= i2c_read(0);

i2c_stop();

}

}

void display_sec0()

{

delay_ms(5);

i2c_start();

i2c_write(0x44);

i2c_write(0x00);

i2c_write(array[a1]); //Display Higher Byte of seconds

i2c_write(0xf7);

i2c_stop();

}

void display_sec1()

{

Page 5: Procedure to Operate PIC

delay_ms(5);

i2c_start();

i2c_write(0x44);

i2c_write(0x00);

i2c_write(array[b1]); //Display Lower Byte of seconds

i2c_write(0xfb);

i2c_stop();

}

void display_min0()

{

delay_ms(5);

i2c_start();

i2c_write(0x44);

i2c_write(0x00);

i2c_write(array[c1]); //Display Higher Byte of minute

i2c_write(0xfd);

i2c_stop();

}

void display_min1()

{

delay_ms(5);

i2c_start();

i2c_write(0x44);

i2c_write(0x00);

i2c_write(array[d1]); //Display Higher Byte of minute

i2c_write(0xfe);

i2c_stop();

}

Page 6: Procedure to Operate PIC

void IC_Config()

{

delay_us(1000);

i2c_start();

i2c_write(0x44);

i2c_write(0x04); //GPIO Register

i2c_write(0x00);

i2c_write(0x00);

i2c_stop();

delay_us(1000);

i2c_start();

i2c_write(0x44);

i2c_write(0x06); //GPIO Register

i2c_write(0x00);

i2c_write(0x00);

i2c_stop();

delay_us(1000);

i2c_start();

i2c_write(0x44);

i2c_write(0x0a); //GPIO Register

i2c_write(0x01);

i2c_write(0x01);

i2c_stop();

delay_us(1000);

}

void alarm_set()

{

Page 7: Procedure to Operate PIC

output_b(0xff);

if(minute==0x57)

{

if((second>=0x10)&&(second<=0x14))

{

output_high(PIN_B0);

delay_ms(10);

output_low(PIN_B0);

delay_ms(10);

}

}

}

void main()

{

IC_Config();

set_rtc_time();

while(1)

{

get_rtc_time();

second = readtime[0];

minute = readtime[1];

printf(" Time : %x : %x \n\r",readtime[1],readtime[0]);

a1 = (second & 0x0f);

b1 = (second & 0xf0);

b1 = b1>>0x04;

Page 8: Procedure to Operate PIC

c1 = (minute & 0x0f);

d1 = (minute & 0xf0);

d1 = d1>>0x04;

display_sec0();

display_sec1();

delay_us(50);

display_min0();

display_min1();

alarm_set();

delay_us(500);

}

}