PDA

View Full Version : [CCSC] LCD.C trong driver CCS C


vohieuthao1
27-10-2008, 01:18 AM
Vì sao mình dùng LCD.C của ccs khi biên dịch thì bị báo lỗi, khi biên dịch thì liên kết với file lcd.c của ccs. Mình dùng file này không chỉnh sửa gì cả. Ai biết chỉ mình với, nếu fai3 chỉnh code cua file lcd.c thi chỉnh như thế nào.

cong1810
27-10-2008, 09:22 AM
đôi khi mình cũng bị lỗi này.nhưng chắc chắn là lcd.c trong driver ko sai.mà sai ở đoạn code của bạn.bạn thử post code lên xem!

vohieuthao1
27-10-2008, 10:25 AM
Mình mới biết pic thôi nên các bạn chỉ kỹ kỹ giùm.

#include <16f877a.h>
#include <def_877a.h>
#device *=16 adc=10
#use delay(clock=4000000)
#include <lcd.c>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use rs232(baud=9600,parity=n,xmit=pin_C6,rcv=pin_C7)
void main()
{
float value;
trisa=0xFF;
trisd=0x00;
lcd_init();
printf(lcd_putc,"0g");
setup_adc_ports(ra1);
setup_adc(ADC_CLOCK_INTERNAL);
delay_us(10);
value=(float)read_adc();
value=value*0.977;
printf(lcd_putc, "Float: %f", value);
}

cong1810
27-10-2008, 09:38 PM
Mình mới biết pic thôi nên các bạn chỉ kỹ kỹ giùm.

#include <16f877a.h>
#include <def_877a.h>
#device *=16 adc=10
#use delay(clock=4000000)
#include <lcd.c>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use rs232(baud=9600,parity=n,xmit=pin_C6,rcv=pin_C7)
void main()
{
float value;
trisa=0xFF;
trisd=0x00;
lcd_init();
printf(lcd_putc,"0g");
setup_adc_ports(ra1);
setup_adc(ADC_CLOCK_INTERNAL);
delay_us(10);
value=(float)read_adc();
value=value*0.977;
printf(lcd_putc, "Float: %f", value);
}
mình đã thử dịch file của bạn.ở đây có vài vần đề thế này!
thứ 1: bạn nên để dòng FUSE lên sau file include <16f877a.h>. và bạn khai báo sai cho PIC nếu thạch anh 4M thì khai báo là XT. mình ko rõ việc cầu hình FUSE sau lệnh #use delay_clock có bị ảnh hưởng gì ko! nhưng thấy ko ai làm thế!!
thứ 2: trong lệnh setup_adc_ports() ko hiều khai báo RA1. bạn nên mở file 16f877a.h .trong đó người ta có liệt kê các cách khai báo đấy!
mình chỉ dịch lại cho bạn.nên ko để ý đến việc bạn đang làm gì!! thân!
đoạn code sau dịch ok!

#include <16f877a.h>
#include <def_877a.h>
#FUSES NOWDT, XT, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#device *=16 adc=10
#use delay(clock=4000000)
#include <lcd.c>
#use rs232(baud=9600,parity=n,xmit=pin_C6,rcv=pin_C7)
void main()
{
float value;
trisa=0xFF;
trisd=0x00;
lcd_init();
printf(lcd_putc,"0g");
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_us(10);
value=(float)read_adc();
value=value*0.977;
printf(lcd_putc, "Float: %f", value);
}

vohieuthao1
28-10-2008, 12:00 AM
Àh, mà bạn có biết cách tạo file hex trong ccs không vậy, mình sửa được rồi nhưng biên dịch mà file hex không thấy ở đâu. Thanks thanks.

vohieuthao1
28-10-2008, 12:08 AM
Bạn ơi, mình có LCD 1602a nhưng muốn dùng chế độ hiển thị 1 hàng. Mình vẫn dùng LCD.C thì có cần sữa file LCD.C không bạn, nếu sữa phải sữa như thế nào.

cong1810
28-10-2008, 11:50 AM
Àh, mà bạn có biết cách tạo file hex trong ccs không vậy, mình sửa được rồi nhưng biên dịch mà file hex không thấy ở đâu. Thanks thanks.

khi bạn dịch thành công thì CCS C đã tạo cho bạn file hẽ rồi đấy. nó nằm cùng với thư mục mà bạn lưu trong chương trình của bạn!!
thân!!

cong1810
28-10-2008, 12:02 PM
Bạn ơi, mình có LCD 1602a nhưng muốn dùng chế độ hiển thị 1 hàng. Mình vẫn dùng LCD.C thì có cần sữa file LCD.C không bạn, nếu sữa phải sữa như thế nào.
mình chưa làm 1 line bao giờ. bởi khi cần xuất trên line nào thì mình có chương trình con sẵn trong file lcd.c là " lcd_gotoxy( BYTE x, BYTE y)" cho phép bạn xuất các vị trí trên LCD.
còn nếu sửa thì mình cho là ở đây:

#ifndef lcd_type
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#endif

bạn thử làm nhé!!!
thân!

vohieuthao1
28-10-2008, 11:25 PM
Các bạn ơi, có ai biết cách thiết lập reset khi cấp nguồn cho Pic 16f887 không?

vohieuthao1
30-10-2008, 01:47 AM
Mình đọc kết quả ADC tính toán xuất kết quả ra LCD, mình muốn dùng ngắt để mỗi khi tác động thì LCD hiển thị giá trị 0 và VDK củng lưu lại giá trị ADC để sau khị thoát khỏi ngắt thì dùng. Giá trị này được update khi ngắt được gọi lần nữa. Mình viết code nhưng khi mô phỏng thì dường như ngắt không chạy. Ai biết chỉ mình với. Hiện mình dùng RB7 nối nguồn thông qua nút ấn để thay đổi trạng thái chân RB7. Không biết mình mắc vậy đúng không?

code:

#include <16f877a.h>
#include <def_877a.h>
#FUSES NOWDT, XT, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#device *=16 adc=10
#use delay(clock=4000000)
#include <thao2.c>// LCD 4bit.c
#use rs232(baud=9600,parity=n,xmit=pin_C6,rcv=pin_C7)



#INT_RB
Void RB_Chuan_Zero ( )
{
float a=0;
a=(float)read_adc();

}

void main()
{
trisb=0xF0;
enable_interrupts ( INT_RB ) ;
enable_interrupts ( GLOBAL ) ;

{
float value=0,a=0;

trisa=0xFF;
trisd=0x00;

LCD_Init ( );
LCD_putcmd(0x84);
LCD_putchar("KHOI LUONG");
LCD_putcmd(0xCA);
LCD_putchar(" g");

start:
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(1);
delay_us(10);
value=(float)read_adc();
value=(value-a)*0.977;
LCD_putcmd(0xC5);
printf(LCD_putchar, "%f", value );
delay_ms( 500 );

goto start;
}
}

hdtspkt
21-11-2009, 11:37 AM
mình không build được,các bạn giúp mình với:

#include<16f877a.h>
#include<def_16f877a.h>
#fuses NOWDT,PUT,HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
Int8 I,ket_qua,tram,chuc,don_vi;
const unsigned char bcd[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};

Void hex_bcd()

{
Tram=ket_qua/100;
Ket_qua=ket_qua%100;
Chuc=ket_qua/10;
Don_vi=ket_qua%10;
}
Void hien_thi() //ham hien thi bang
//phuong phap quet
{
I=0;
While (i<200)
{
Portc=bcd[don_vi];
Portd=0xfb;
Delay_us(100);
Portc=bcd[chuc];
Portd=0xfd;
Delay_us(100);
Portc=bcd[tram];
Portd=0xfe;
Delay_us(100);
I++;
}
}
Void main()
{
Trisd=0x00;
Trisc=0x00;

Setup_adc(adc_clock_internal);

Setup_adc_ports(AN0_VREF_VREF);

Set_adc_channel(0);
Delay_ms(10);
While(true)
{
Ket_qua=read_adc();
hex_bcd();
hien_thi();
}
}

hellongaymoi
08-12-2009, 11:44 PM
các huynh có file def_877a.h ko gửi cho em với được ko.em viet chuong trinh khi biên dịch fife hex thì nó báo lỗi ko mở đc file def_877a.h.

phamdinh
10-02-2010, 11:03 AM
các huynh có file def_877a.h ko gửi cho em với được ko.em viet chuong trinh khi biên dịch fife hex thì nó báo lỗi ko mở đc file def_877a.h.

Mình cũng bị như bạn. Mình tìm hiểu thì thấy như sau. Nếu bạn dùng PIC C compiler ver3.227 thì trong thư mục devices(nằm trong ổ mà bạn cài chương trình) sẽ không có thư viện này. Bạn có thể chép nó từ một ver cao hơn hoặc tốt nhất là bạn nên update phiên bản mới.

vupromax7209
07-05-2012, 04:51 PM
khi mình khai báo thư viện <LCD.c> thì chương trình mình bị lỗi delay ha?,khó hiểu quá.
chương trình như sau:



#include <16F877a.h>
#FUSES NOWDT, HS ,NOPROTECT, NODEBUG, NOPUT, NOCPD, NOWRT
#include <def_877a.h>
#include <lcd.c>
#use delay(clock=20000000)
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
//==================khai bao ham con=============
int quetphim();
int checkphim(b);
void pwm();
void ghi_tocdo();
void ghi_thoigian();
void clear();
void read_rom();
//==================khai bao bien================
int8 i,t,a,b,c,d,sttphim,duty,ct,l,m;
int16 s_xung,s_vong,setpoint,error,luu,tg,tg1,dem;
//================ bien luu eeprom==============
int8 e0,e1,e2,e3,j,k;
int16 e;
//================chuong trinh quet phim==========
//quet phim so
int quetphim()
{
output_b(0xe0);// B4=0
a=0;
b=1;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}
output_b(0xd0);// B5=0
a=0;
b=2;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}
output_b(0xb0);// B6=0
a=0;
b=3;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}
output_b(0x70);// B6=0
a=0;
b=4;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}}

//============chuong trinh check phim=============
int checkphim(b)
{
switch (b)
{
case 1:
if(!input(pin_a0))
{sttphim=1;
a=1;}
else if(!input(pin_a1))
{sttphim=2;
a=1;}
else if(!input(pin_a2))
{sttphim=3;
a=1;}
else if(!input(pin_a3))
{ sttphim=10;//thuan
a=1;}
else {}
break;

case 2:
if(!input(pin_a0))
{sttphim=4;
a=1;}
else if(!input(pin_a1))
{sttphim=5;
a=1;}
else if(!input(pin_a2))
{sttphim=6;
a=1;}
else if(!input(pin_a3))
{sttphim=11;//nghich
a=1;}
else {}
break;
case 3:
if(!input(pin_a0))
{sttphim=7;
a=1;}
else if(!input(pin_a1))
{sttphim=8;
a=1;}
else if(!input(pin_a2))
{sttphim=9;
a=1;}
else if(!input(pin_a3))
{sttphim=12;//stop
a=1;}
else {}
break;

case 4:
if(!input(pin_a0))
{sttphim=0;//0
a=1;}
else if(!input(pin_a1))
{sttphim=15;//save
a=1;}
else if(!input(pin_a2))
{sttphim=14;//clear
a=1;}
else if(!input(pin_a3))
{sttphim=13;//set
a=1;}
else {}
break;}
return (sttphim);
}
// chuong trinh nhan xung tu encoder
//ngat ngoai, nhan xung tu encoder
#int_ext
void RB0_isr()
{
s_xung++;//dem so xung o chan RB0
}
//ngat timer1, tinh toan pwm va hien thi
#int_timer1
void timer1_isr()
{
set_timer1(-62500);
if (t==5){
S_vong=s_xung*2;//xung tren phut
//ht
lcd_gotoxy(1,1);
printf(lcd_putc," ");
if(ct==1)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=%lu v/p",luu);}
else {
lcd_gotoxy(1,1);
printf(lcd_putc,"TG_dat=%lu s",tg);}
lcd_gotoxy(1,2);
printf(lcd_putc," ");
if (d==2)
{lcd_gotoxy(1,2);
printf(lcd_putc,"TD_tt=-%luv/p",s_vong);}
if (d==1)
{lcd_gotoxy(1,2);
printf(lcd_putc,"TD_tt= %luv/p",s_vong);}
//=========================
//xuat pwm
pwm();
//========================
s_xung=0;
s_vong=0;
t=0;
set_timer1(-62500);
}
else
t++;
set_timer1(-62500);
}
//ngat timer0, dat thoi gian
#int_timer0
void time0_irs()
{
set_timer0(-235);
if (dem>=tg1)
{
output_high(pin_e0);
delay_us(100);
output_low(pin_e0);
dem=0;
if (d==1)
{d=2;}
else if (d==2)
{d=1;}
else{}
set_timer0(-235);
}
else {
dem++;
set_timer0(-235);}
}
//chuong trinh chinh
void main()
{
i=0;
sttphim=0;
setpoint=0;tg=0;
duty=0;
c=0;
d=0;
ct=0;l=0;m=0;
e0=0;e1=0;e2=0;e3=0;e=0;k=0;
//================================================== ==========
//1:ngo vao;0: la ngo ra
set_tris_b(0b00001111);//4 chan RB4-RB7 xuat du lieu ra ban phim
set_tris_a(0b00001111);//4 chan RA0-RA3 nhan du lieu tu ban phim
set_tris_c(0b00000000);//2 chan RC0 va RC1 xuat PWM
set_tris_D(0b00000000);//port D la port xuat du lieu ra LCD
//================================================== ==========
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
/* timer1 la bo dinh thoi su dung xung noi,bo chia 1:8 thay doi moi 1600ns
Dung timer1 de ngat moi 0.1s do vay ta dat gia tri cho timer1 la :
0.1s/1600ns=62500(D)=F424(H) =>gia tri nap la FFFF-F424=BDB*/
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
enable_interrupts(int_ext);//khoi dong ngat ngoai
ext_int_edge(H_TO_L); // xung tu cao xuong thap
enable_interrupts(global);// khoi dong bit ngat GIE
setup_timer_2(T2_DIV_BY_4,249,1);
/*timer2 dung dinh thoi cho bo PWM
mode: bo chia thoi gian (prescale) cua timer2 1:4
period: gia tri nap chi thanh ghi PR2
postscale : bo chi ra,chon 1:1 PWM khong dung
Thach anh 20MHz, PWM fre: 10000Hz, thay doi duty cycle(%) de thay doi toc do*/
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
set_pwm1_duty(0);
set_pwm2_duty(0);
//================================================== =========
lcd_init();
lcd_send_byte(0,0x01);
lcd_gotoxy(1,1);
printf(lcd_putc,"CHUONG TRINH DK ");
lcd_gotoxy(1,2);
printf(lcd_putc," TD DONG CO DC ");
delay_ms(1000);
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," ");
read_rom();
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_ ");
while (true)
{
while (c==0)
{
quetphim();
if (a!=0)
{
if (sttphim==1)
{ ct=1;
c=1;
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_%u",ct);}
if (sttphim==2)
{ ct=2;
c=1;
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_%u",ct);}
}
}
if (ct==1)
{lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_ v/p");
lcd_gotoxy(1,2);
printf(lcd_putc,"TD_luu=%lu v/p",e);}
else {
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_ v/p");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=_ s");}
While (c==1)
{
quetphim();

if (a!=0)
{
if (sttphim>=0 && sttphim<=9)//ban phim tu 0--->9
{
if (m==0)
{ghi_tocdo();}
if((ct==2)&&(m==1))
{ghi_thoigian();}
}
if (sttphim==14)
{clear();}
if ((sttphim==13)&&(i==0)&&(e==0))
{
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"Phai nhap TD_dat");
delay_ms(1000);
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_");
}
if ((sttphim==15)&&(i!=0)) //luu vao eeprom
{
write_eeprom(0,e0);
delay_ms(100);
write_eeprom(1,e1);
delay_ms(100);
write_eeprom(2,e2);
delay_ms(100);
write_eeprom(3,e3);
delay_ms(100);
write_eeprom(4,i);
delay_ms(100);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," LUU THANH CONG ");
}
if ((sttphim==13)&&((i!=0)||(e!=0)))
{
if (ct==1)
{
c=2;
if (e!=0 && i==0)
luu=e;}
if ((ct==2)&&(l>=2))
{
c=2;}
m=1;
}}}
while (c==2)
{
quetphim();
if(a!=0)
{
if(sttphim==10)
{
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," QUAY THUAN ");
if (ct==2)
{enable_interrupts(int_timer0);
set_timer1(-235);}
enable_interrupts(int_timer1);
enable_interrupts(global);
set_timer1(-62500);
set_pwm1_duty(duty);
d=1;
}
if (sttphim==11)
{
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," QUAY NGHICH ");
if (ct==2)
{enable_interrupts(int_timer0);
set_timer1(-235);}
enable_interrupts(int_timer1);
enable_interrupts(global);
set_timer1(-62500);
set_pwm2_duty(duty);
d=2;
}
if (sttphim==12)//stop
{
disable_interrupts(int_timer0);
set_timer0(0);
disable_interrupts(int_timer1);
set_pwm1_duty(0);
set_pwm2_duty(0);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," STOP ");
duty=0;
d=0;
}
if (sttphim==14)
{
clear();
c=0;
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_ ");
}}}}}


void pwm()
{
if ((luu>s_vong)&& duty<250)
{error=luu-s_vong;
if (error>1000)
duty=duty+50;
else if (error>100)
duty=duty+20;
else if (error>30)
{duty=duty+5;}
else if (error>20)
duty=duty+1.5;
else if (error>10)
duty=duty+(0.05*error);
else {duty=duty+(0.025*error);}
}
if (luu<(s_vong-2)&& (duty>0))
{error=s_vong-luu;
if (error>=10)
duty=duty-(0.05*error);
else (duty=duty-(0.02*error));
}
if(luu==s_vong)
duty=duty;
if((duty>=250)&&(luu>s_vong))
{ lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc," TD_tt=MAX ");}
if (d==0)
{set_pwm1_duty(0);
set_pwm2_duty(0);}
else if (d==1)
{set_pwm1_duty(duty);
set_pwm2_duty(0);}
else
{set_pwm1_duty(0);
set_pwm2_duty(duty);}
}
//========chuong trinh con nhap toc do=======
void ghi_tocdo()
{
if(i>=0&&i<=3)
{
// giai thuat luu eeprom
if (i==0)
e0=sttphim;
else if (i==1)
e1=sttphim;
else if (i==2)
e2=sttphim;
else {e3=sttphim;}
//===============================
setpoint*=10;
setpoint+=sttphim;
i++;
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=%lu v/p",setpoint);
luu=setpoint;
}
else {
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"0<TD_dat<=9999");
delay_ms(1000);
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=%lu s",setpoint);
}}
//=========chuong trình con nhap thoi gian=========
void ghi_thoigian()
{
if(l>=0&&l<=3)
{
tg*=10;
tg+=sttphim;
l++;
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=%lu s",tg);
tg1=tg/0.12;
}
else {
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," 0<TG_dat<=999 ");
delay_ms(1000);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=%lu s",tg);
}}
//============chuong trinh con clear=========
void clear()
{
setpoint=0;
tg=0;
i=0;l=0;m=0;
e0=0;e1=0;e2=0;e3=0;
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_");
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=_");
}
//=======chuong trinh con luu toc do vao epprom======
void read_rom()
{
k=read_eeprom(4);
for (j=0;j<k;j++)
{
e=e*10;
e=e+read_eeprom(j);
}}



MÌNH KHÔNG HIỂU SAO KHI MÌNH DỊCH THÌ CHƯƠNG TRÌNH BÁO LỖI FILE <LCD.c>??????,mong mí bạn giúp mình với

tinh08260491
08-05-2012, 05:42 PM
vậy thì nên xem lại file lcd.h chắc file lcd.h này có vấn đề.nếu được bạn nên viết luôn file lcd này luôn đi.khỏi cần dùng cái của người khác .MÌnh viết thì mình mới làm chủ được file lcd này nó làm nhiệm vụ gì.Còn nếu sài thư viện lcd.h của người khác thì bạn thử kiếm file lcd.h của người khác thay vào xem thế nào.

daicap
09-06-2012, 10:30 AM
khi mình khai báo thư viện <LCD.c> thì chương trình mình bị lỗi delay ha?,khó hiểu quá.
chương trình như sau:



#include <16F877a.h>
#FUSES NOWDT, HS ,NOPROTECT, NODEBUG, NOPUT, NOCPD, NOWRT
#include <def_877a.h>
#use delay(clock=20000000)
#include <lcd.c>
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
//==================khai bao ham con=============
int quetphim();
int checkphim(b);
void pwm();
void ghi_tocdo();
void ghi_thoigian();
void clear();
void read_rom();
//==================khai bao bien================
int8 i,t,a,b,c,d,sttphim,duty,ct,l,m;
int16 s_xung,s_vong,setpoint,error,luu,tg,tg1,dem;
//================ bien luu eeprom==============
int8 e0,e1,e2,e3,j,k;
int16 e;
//================chuong trinh quet phim==========
//quet phim so
int quetphim()
{
output_b(0xe0);// B4=0
a=0;
b=1;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}
output_b(0xd0);// B5=0
a=0;
b=2;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}
output_b(0xb0);// B6=0
a=0;
b=3;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}
output_b(0x70);// B6=0
a=0;
b=4;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}}

//============chuong trinh check phim=============
int checkphim(b)
{
switch (b)
{
case 1:
if(!input(pin_a0))
{sttphim=1;
a=1;}
else if(!input(pin_a1))
{sttphim=2;
a=1;}
else if(!input(pin_a2))
{sttphim=3;
a=1;}
else if(!input(pin_a3))
{ sttphim=10;//thuan
a=1;}
else {}
break;

case 2:
if(!input(pin_a0))
{sttphim=4;
a=1;}
else if(!input(pin_a1))
{sttphim=5;
a=1;}
else if(!input(pin_a2))
{sttphim=6;
a=1;}
else if(!input(pin_a3))
{sttphim=11;//nghich
a=1;}
else {}
break;
case 3:
if(!input(pin_a0))
{sttphim=7;
a=1;}
else if(!input(pin_a1))
{sttphim=8;
a=1;}
else if(!input(pin_a2))
{sttphim=9;
a=1;}
else if(!input(pin_a3))
{sttphim=12;//stop
a=1;}
else {}
break;

case 4:
if(!input(pin_a0))
{sttphim=0;//0
a=1;}
else if(!input(pin_a1))
{sttphim=15;//save
a=1;}
else if(!input(pin_a2))
{sttphim=14;//clear
a=1;}
else if(!input(pin_a3))
{sttphim=13;//set
a=1;}
else {}
break;}
return (sttphim);
}
// chuong trinh nhan xung tu encoder
//ngat ngoai, nhan xung tu encoder
#int_ext
void RB0_isr()
{
s_xung++;//dem so xung o chan RB0
}
//ngat timer1, tinh toan pwm va hien thi
#int_timer1
void timer1_isr()
{
set_timer1(-62500);
if (t==5){
S_vong=s_xung*2;//xung tren phut
//ht
lcd_gotoxy(1,1);
printf(lcd_putc," ");
if(ct==1)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=%lu v/p",luu);}
else {
lcd_gotoxy(1,1);
printf(lcd_putc,"TG_dat=%lu s",tg);}
lcd_gotoxy(1,2);
printf(lcd_putc," ");
if (d==2)
{lcd_gotoxy(1,2);
printf(lcd_putc,"TD_tt=-%luv/p",s_vong);}
if (d==1)
{lcd_gotoxy(1,2);
printf(lcd_putc,"TD_tt= %luv/p",s_vong);}
//=========================
//xuat pwm
pwm();
//========================
s_xung=0;
s_vong=0;
t=0;
set_timer1(-62500);
}
else
t++;
set_timer1(-62500);
}
//ngat timer0, dat thoi gian
#int_timer0
void time0_irs()
{
set_timer0(-235);
if (dem>=tg1)
{
output_high(pin_e0);
delay_us(100);
output_low(pin_e0);
dem=0;
if (d==1)
{d=2;}
else if (d==2)
{d=1;}
else{}
set_timer0(-235);
}
else {
dem++;
set_timer0(-235);}
}
//chuong trinh chinh
void main()
{
i=0;
sttphim=0;
setpoint=0;tg=0;
duty=0;
c=0;
d=0;
ct=0;l=0;m=0;
e0=0;e1=0;e2=0;e3=0;e=0;k=0;
//================================================== ==========
//1:ngo vao;0: la ngo ra
set_tris_b(0b00001111);//4 chan RB4-RB7 xuat du lieu ra ban phim
set_tris_a(0b00001111);//4 chan RA0-RA3 nhan du lieu tu ban phim
set_tris_c(0b00000000);//2 chan RC0 va RC1 xuat PWM
set_tris_D(0b00000000);//port D la port xuat du lieu ra LCD
//================================================== ==========
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
/* timer1 la bo dinh thoi su dung xung noi,bo chia 1:8 thay doi moi 1600ns
Dung timer1 de ngat moi 0.1s do vay ta dat gia tri cho timer1 la :
0.1s/1600ns=62500(D)=F424(H) =>gia tri nap la FFFF-F424=BDB*/
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
enable_interrupts(int_ext);//khoi dong ngat ngoai
ext_int_edge(H_TO_L); // xung tu cao xuong thap
enable_interrupts(global);// khoi dong bit ngat GIE
setup_timer_2(T2_DIV_BY_4,249,1);
/*timer2 dung dinh thoi cho bo PWM
mode: bo chia thoi gian (prescale) cua timer2 1:4
period: gia tri nap chi thanh ghi PR2
postscale : bo chi ra,chon 1:1 PWM khong dung
Thach anh 20MHz, PWM fre: 10000Hz, thay doi duty cycle(%) de thay doi toc do*/
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
set_pwm1_duty(0);
set_pwm2_duty(0);
//================================================== =========
lcd_init();
lcd_send_byte(0,0x01);
lcd_gotoxy(1,1);
printf(lcd_putc,"CHUONG TRINH DK ");
lcd_gotoxy(1,2);
printf(lcd_putc," TD DONG CO DC ");
delay_ms(1000);
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," ");
read_rom();
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_ ");
while (true)
{
while (c==0)
{
quetphim();
if (a!=0)
{
if (sttphim==1)
{ ct=1;
c=1;
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_%u",ct);}
if (sttphim==2)
{ ct=2;
c=1;
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_%u",ct);}
}
}
if (ct==1)
{lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_ v/p");
lcd_gotoxy(1,2);
printf(lcd_putc,"TD_luu=%lu v/p",e);}
else {
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_ v/p");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=_ s");}
While (c==1)
{
quetphim();

if (a!=0)
{
if (sttphim>=0 && sttphim<=9)//ban phim tu 0--->9
{
if (m==0)
{ghi_tocdo();}
if((ct==2)&&(m==1))
{ghi_thoigian();}
}
if (sttphim==14)
{clear();}
if ((sttphim==13)&&(i==0)&&(e==0))
{
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"Phai nhap TD_dat");
delay_ms(1000);
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_");
}
if ((sttphim==15)&&(i!=0)) //luu vao eeprom
{
write_eeprom(0,e0);
delay_ms(100);
write_eeprom(1,e1);
delay_ms(100);
write_eeprom(2,e2);
delay_ms(100);
write_eeprom(3,e3);
delay_ms(100);
write_eeprom(4,i);
delay_ms(100);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," LUU THANH CONG ");
}
if ((sttphim==13)&&((i!=0)||(e!=0)))
{
if (ct==1)
{
c=2;
if (e!=0 && i==0)
luu=e;}
if ((ct==2)&&(l>=2))
{
c=2;}
m=1;
}}}
while (c==2)
{
quetphim();
if(a!=0)
{
if(sttphim==10)
{
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," QUAY THUAN ");
if (ct==2)
{enable_interrupts(int_timer0);
set_timer1(-235);}
enable_interrupts(int_timer1);
enable_interrupts(global);
set_timer1(-62500);
set_pwm1_duty(duty);
d=1;
}
if (sttphim==11)
{
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," QUAY NGHICH ");
if (ct==2)
{enable_interrupts(int_timer0);
set_timer1(-235);}
enable_interrupts(int_timer1);
enable_interrupts(global);
set_timer1(-62500);
set_pwm2_duty(duty);
d=2;
}
if (sttphim==12)//stop
{
disable_interrupts(int_timer0);
set_timer0(0);
disable_interrupts(int_timer1);
set_pwm1_duty(0);
set_pwm2_duty(0);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," STOP ");
duty=0;
d=0;
}
if (sttphim==14)
{
clear();
c=0;
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_ ");
}}}}}


void pwm()
{
if ((luu>s_vong)&& duty<250)
{error=luu-s_vong;
if (error>1000)
duty=duty+50;
else if (error>100)
duty=duty+20;
else if (error>30)
{duty=duty+5;}
else if (error>20)
duty=duty+1.5;
else if (error>10)
duty=duty+(0.05*error);
else {duty=duty+(0.025*error);}
}
if (luu<(s_vong-2)&& (duty>0))
{error=s_vong-luu;
if (error>=10)
duty=duty-(0.05*error);
else (duty=duty-(0.02*error));
}
if(luu==s_vong)
duty=duty;
if((duty>=250)&&(luu>s_vong))
{ lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc," TD_tt=MAX ");}
if (d==0)
{set_pwm1_duty(0);
set_pwm2_duty(0);}
else if (d==1)
{set_pwm1_duty(duty);
set_pwm2_duty(0);}
else
{set_pwm1_duty(0);
set_pwm2_duty(duty);}
}
//========chuong trinh con nhap toc do=======
void ghi_tocdo()
{
if(i>=0&&i<=3)
{
// giai thuat luu eeprom
if (i==0)
e0=sttphim;
else if (i==1)
e1=sttphim;
else if (i==2)
e2=sttphim;
else {e3=sttphim;}
//===============================
setpoint*=10;
setpoint+=sttphim;
i++;
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=%lu v/p",setpoint);
luu=setpoint;
}
else {
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"0<TD_dat<=9999");
delay_ms(1000);
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=%lu s",setpoint);
}}
//=========chuong trình con nhap thoi gian=========
void ghi_thoigian()
{
if(l>=0&&l<=3)
{
tg*=10;
tg+=sttphim;
l++;
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=%lu s",tg);
tg1=tg/0.12;
}
else {
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," 0<TG_dat<=999 ");
delay_ms(1000);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=%lu s",tg);
}}
//============chuong trinh con clear=========
void clear()
{
setpoint=0;
tg=0;
i=0;l=0;m=0;
e0=0;e1=0;e2=0;e3=0;
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_");
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=_");
}
//=======chuong trinh con luu toc do vao epprom======
void read_rom()
{
k=read_eeprom(4);
for (j=0;j<k;j++)
{
e=e*10;
e=e+read_eeprom(j);
}}



MÌNH KHÔNG HIỂU SAO KHI MÌNH DỊCH THÌ CHƯƠNG TRÌNH BÁO LỖI FILE <LCD.c>??????,mong mí bạn giúp mình với
bạn khai báo sử dunhj thạch anh trên hàm gọi lcd như mình sủa ở trên
#use delay(clock=20M)
#include"lcd.c"