Mọi người cho em hỏi là code trong CCS là sử dụng pic 16f877a nhưng giờ hiện tại mạch em đang sử dụng PIC 16F887 thì chỉnh sửa CODE như thế nào cho phù hợp ạ.
CODE của em đây( em đã đổi tên thành PIC 16F887 nhưng nạp vào không chạy.
#include <16F877a.h>
#fuses NOWDT,HS,NOPUT,NOPROTECT,NODEBUG,NOBROWNOUT,NOLVP, NOCPD,NOWRT
#use delay(clock=20000000,RESTART_WDT) // Sets crystal oscillator at 20 megahertz
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) //Sets up serial port output pin & baud rate
#include "lcd_LIB.c"
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)
#byte PORTA =0x05
#byte PORTB =0x06
#byte PORTC =0x07
#byte PORTD =0x08
#byte PORTE =0x09
#byte TRISA =0x85
#byte TRISB =0x86
#byte TRISC =0x87
#byte TRISD =0x88
#byte TRISE =0x89
#bit RB0=0x06.0
#bit RB1=0x06.1
#bit RB2=0x06.2
#bit RB3=0x06.3
#bit RB4=0x06.4
#bit RB5=0x06.5
int8 value[3],count=0,i=0;
int8 string[16];
//========Interrupts RS232=========
#INT_RDA
void RDA_interrupt(){
value[0] = getc();
if (value[0]==1)
{
value[1] = getc();
value[2] = getc();
switch(value[1]){
case 1:
if (value[2]==1)
RB0=0;
else RB0=1;
break;
case 2:
if (value[2]==1)
RB1=0;
else RB1=1;
break;
case 3:
if (value[2]==1)
RB2=0;
else RB2=1;
break;
case 4:
if (value[2]==1)
RB3=0;
else RB3=1;
break;
case 5:
if (value[2]==1)
RB4=0;
else RB4=1;
break;
case 6:
if (value[2]==1)
RB5=0;
else RB5=1;
break;
}}
if (value[0]==2)
{
for (i=0;i<16;i++)
{
string[i]="";
}
count=getc();
for (i=0;i<count;i++)
{
string[i]=getc();
}
delay_us(10);
for (i=0;i<count;i++)
{
putc(string[i]);
}
}
delay_us(100);
}
//++++++++++++++++Main Function+++++++++++++++++++
void main()
{
TRISB=0x00;
PORTB=0xff;
TRISD=0x00;
ENABLE_INTERRUPTS(INT_RDA);
enable_interrupts(GLOBAL);
lcd_init();
while(true)
{
lcd_putcmd(line_1);
lcd_putchar('K');
delay_ms(300);
lcd_putchar('I');
delay_ms(300);
lcd_putchar('N');
delay_ms(300);
lcd_putchar('H');
delay_ms(300);
lcd_putchar('C');
delay_ms(300);
lcd_putchar('H');
delay_ms(300);
lcd_putchar('A');
delay_ms(300);
lcd_putchar('O');
delay_ms(300);
lcd_putchar(' ');
delay_ms(300);
printf(lcd_putchar,"CAC BAN");
delay_ms(500);
lcd_putcmd(line_2);
printf(lcd_putchar, "%s", string);
delay_ms(1000);
lcd_putcmd(Clear_Scr);
}
}
CODE của em đây( em đã đổi tên thành PIC 16F887 nhưng nạp vào không chạy.
#include <16F877a.h>
#fuses NOWDT,HS,NOPUT,NOPROTECT,NODEBUG,NOBROWNOUT,NOLVP, NOCPD,NOWRT
#use delay(clock=20000000,RESTART_WDT) // Sets crystal oscillator at 20 megahertz
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) //Sets up serial port output pin & baud rate
#include "lcd_LIB.c"
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)
#byte PORTA =0x05
#byte PORTB =0x06
#byte PORTC =0x07
#byte PORTD =0x08
#byte PORTE =0x09
#byte TRISA =0x85
#byte TRISB =0x86
#byte TRISC =0x87
#byte TRISD =0x88
#byte TRISE =0x89
#bit RB0=0x06.0
#bit RB1=0x06.1
#bit RB2=0x06.2
#bit RB3=0x06.3
#bit RB4=0x06.4
#bit RB5=0x06.5
int8 value[3],count=0,i=0;
int8 string[16];
//========Interrupts RS232=========
#INT_RDA
void RDA_interrupt(){
value[0] = getc();
if (value[0]==1)
{
value[1] = getc();
value[2] = getc();
switch(value[1]){
case 1:
if (value[2]==1)
RB0=0;
else RB0=1;
break;
case 2:
if (value[2]==1)
RB1=0;
else RB1=1;
break;
case 3:
if (value[2]==1)
RB2=0;
else RB2=1;
break;
case 4:
if (value[2]==1)
RB3=0;
else RB3=1;
break;
case 5:
if (value[2]==1)
RB4=0;
else RB4=1;
break;
case 6:
if (value[2]==1)
RB5=0;
else RB5=1;
break;
}}
if (value[0]==2)
{
for (i=0;i<16;i++)
{
string[i]="";
}
count=getc();
for (i=0;i<count;i++)
{
string[i]=getc();
}
delay_us(10);
for (i=0;i<count;i++)
{
putc(string[i]);
}
}
delay_us(100);
}
//++++++++++++++++Main Function+++++++++++++++++++
void main()
{
TRISB=0x00;
PORTB=0xff;
TRISD=0x00;
ENABLE_INTERRUPTS(INT_RDA);
enable_interrupts(GLOBAL);
lcd_init();
while(true)
{
lcd_putcmd(line_1);
lcd_putchar('K');
delay_ms(300);
lcd_putchar('I');
delay_ms(300);
lcd_putchar('N');
delay_ms(300);
lcd_putchar('H');
delay_ms(300);
lcd_putchar('C');
delay_ms(300);
lcd_putchar('H');
delay_ms(300);
lcd_putchar('A');
delay_ms(300);
lcd_putchar('O');
delay_ms(300);
lcd_putchar(' ');
delay_ms(300);
printf(lcd_putchar,"CAC BAN");
delay_ms(500);
lcd_putcmd(line_2);
printf(lcd_putchar, "%s", string);
delay_ms(1000);
lcd_putcmd(Clear_Scr);
}
}