PDA

View Full Version : Lỗi khi Compile sang file HEX


giangtieungu08
10-07-2009, 08:22 PM
//CHUONG TRINH HIEN TAI CAC NUT CHUC NANG CHUA HOAT DONG
//XEM LAI CLEAR KHONG THE
//KHONG THE GIAU SO DA NHAP
#include <16f877a.h>
#fuses NOWDT,XT,NOPROTECT,NOLVP,PUT
#use delay(clock=4000000)

#include <lcd.c>

#use fast_io(b)
#byte portB=0x06
#use fast_io(b)
#byte portc=0x07
#use fast_io(b)
#byte portD=0x08
#use fast_io(b)
#byte portE=0x09
#bit RS = portE.2
#bit RW = portE.1
#bit E = portE.0
#bit c0=portc.0
#bit c1=portc.1

#define LCD PortB
const unsigned char dig[]= {'M','O','I',' ','N','H','A','P',' ','P','A','S','S',':','#'};
int8 i,j,a=0;
int8 nhap_mk();
void dat_mk();
void tao_mk_moi();
void enter();

int8 mk;
int8 ch;
void command()
{
RS = 0; //ghi lenh
RW = 0;
E = 1;
E = 0;
delay_ms(6);
}
void display()
{
RS = 1;//ghi du lieu
RW = 0;
E = 1;
E = 0;
delay_ms(6);
}
//**********kiem tra mat khau***************
void kt_mk()
{
int8 kt;

if(c0==0)
{
delay_ms(50);
if (c0 == 0)
{
kt = read_eeprom(0x00);
if (kt == 0)
dat_mk();
else
tao_mk_moi();
}
}

if(c1 == 0)
{
delay_ms(50);
if(c1 == 0)
enter();
}
}
//********************************************
void dat_mk()
{
lcd_gotoxy(0, 1);
lcd_putc("hap mb");
delay_ms(100);
mk = nhap_mk();
write_eeprom(0x00, mk);
delay_ms(10);
lcd_gotoxy(10, 1);
lcd_putc("ghi hoan tat");
}
//*********************tao mk moi
void tao_mk_moi()
{
lcd_gotoxy(2, 1);
lcd_putc("mk cu");
delay_ms(100);
mk = nhap_mk();
if(mk == read_eeprom(0x00))
{
delay_ms(10);
lcd_gotoxy(4, 1);
lcd_putc("mk moi");
delay_ms(100);
mk = nhap_mk();
write_eeprom(0x00, mk);
lcd_gotoxy(11, 1);
lcd_putc("ghi hoan tat");
delay_ms(100);
}
else
{
lcd_gotoxy(7, 1);
lcd_putc("sai ma");
delay_ms(100);
}
}
//********************enter*************
void enter()
{
lcd_gotoxy(3, 1);
lcd_putc("Password??");
delay_ms(100);
mk = nhap_mk();

if(mk == read_eeprom(0x00))
{
lcd_gotoxy(4, 1);
lcd_putc("You're welcom");
delay_ms(100);
}
else
{
lcd_gotoxy(7, 1);
lcd_putc("Wrong pass!");
delay_ms(100);
}
}
//***********ghi eeprom*********
void ghi_eeprom(int8 ch)
{
write_eeprom(0x00, ch);
}
//*********************************
int8 doc_eeprom()
{
int8 ch;
ch = read_eeprom(0x00);
return ch;
}
//********************************************
void main()
{
Set_tris_B(0);
Set_tris_E(0);
delay_ms(100); //thoi gian de LCD hien thi
LCD = 0x38; //Hai hang, ma tran 5x7, b bit
command();
LCD = 0x0C; //Bat hien thi, tat con tro
command();
LCD = 0x80; //Vi tri hang 1, cot ?; Ve dau dong 1
command();
//----------------------------------------
//----------------------------------------
While(dig[a]!='#')
{
portB=dig[a];
display();
delay_ms(100);
a++;
}
output_b(0xC0); //Ve dau dong 2
command();
delay_ms(100);
output_d(0b11111111);
while(1)
{
int8 nhap_mk()
{
int8 mk;
//***************************************
//***************************************
output_d(0b01111111); //Hang 0 chan RD7 xuong muc 0
delay_ms(10);
if(input(pin_D3)==0) //cho D3 xuong muc 0
mk = 0x10;
{
output_b('A'); //ghi A
display();
delay_ms(150);
}
if(input(pin_D2)==0) //cho D2 xuong muc 0
mk = 0x00;
{
output_b(0x30); //ghi 0
display();
delay_ms(150);
}
if(input(pin_D1)==0) //cho D1 xuong muc 0
mk = 0x11;
{
output_b('#'); //ghi #
display();
delay_ms(150);
}

//***************************************
output_d(0b10111111); //Hang 1 chan RD6 xuong muc 0
delay_ms(10);
if(input(pin_D3)==0) //cho D3 xuong muc 0
mk = 0x01;
{
output_b(0x31); //ghi 1
display();
delay_ms(150);
}
if(input(pin_D2)==0) //cho D2 xuong muc 0
mk = 0x02;
{
output_b(0x32); //ghi 2
display();
delay_ms(150);
}
if(input(pin_D1)==0) //cho D1 xuong muc 0
mk = 0x03;
{
output_b(0x33); //ghi 3
display();
delay_ms(150);
}

//***************************************
output_d(0b11011111); //Hang 2 chan RD5 xuong muc 0
delay_ms(10);
if(input(pin_D3)==0) //cho D3 xuong muc 0
mk = 0x04;
{
output_b(0x34); //ghi 4
display();
delay_ms(150);
}
if(input(pin_D2)==0) //cho D2 xuong muc 0
mk = 0x05;
{
output_b(0x35); //ghi 5
display();
delay_ms(150);
}
if(input(pin_D1)==0) //cho D1 xuong muc 0
mk = 0x06;
{
output_b(0x36); //ghi 6
display();
delay_ms(150);
}

//*****************************************
output_d(0b11101111); //Hang 3 chan RD4 xuong muc 0
delay_ms(10);
if(input(pin_D3)==0) //cho D3 xuong muc 0
mk = 0x07;
{
output_b(0x37); //ghi 7
display();
delay_ms(150);
}
if(input(pin_D2)==0) //cho D2 xuong muc 0
mk = 0x08;
{
output_b(0x38); //ghi 8
display();
delay_ms(150);
}
if(input(pin_D1)==0) //cho D1 xuong muc 0
mk = 0x09;
{
output_b(0x39); //ghi 9
display();
delay_ms(150);
}
return mk;
}
}
}




Lúc mình compile sang file hex thì nó báo lỗi như sau:

giangtieungu08
10-07-2009, 10:11 PM
các pro có ai sửa đc jup với, mình đang làm bt về nó mà lại mới n/c nữa nên cùng ko rành lắm về cả PIC lẫn CCS. Thanks

giangtieungu08
11-07-2009, 12:07 AM
cám ơn ngocthanh07, mình coi rồi nhưng nó chỗ đó nó không báo lỗi. Mà nó báo lỗi ngay dòng 178 .output_d(0b01111111); . Hình như là lỗi khai báo biến hay sao ấy. Mình sửa mãi mà ko đc. Có ai xửa đc jup mình với. Thanks.

giangtieungu08
11-07-2009, 12:26 AM
sr, mình không có ý j cả, tại mình compile nó báo lỗi ở đó. Chứ CCS mình còn gà lắm, mới làm quen nó đúng 1 tuần đây nè. Bạn có cách nào chỉ rõ cho mình chút di. Thanks

giangtieungu08
11-07-2009, 12:34 AM
ừh, thanks nha, để mình thử lại xem sao. Từ tối tới giờ loay woay woai cái lỗi này.

giangtieungu08
11-07-2009, 12:49 AM
cám ơn, ngocthanh07 nha, đúng là lỗi ở chỗ return thật. Nhưng bây giờ nó chạy loạn xạ luôn. Ah sẵn đây cho mình hỏi, mình viết ct nhập bàn phím hiển thị lên LCD, nếu ko xài ngắt thì OK nhưng cho thêm ngắt vào thì lại bị lỗi. Ko biết làm j luôn

quangvanvo
08-01-2011, 09:17 AM
em mới viết code lần đầu nên nó báo lỗi mà em thật sự không biết tại sao
đây là đoạn code ma có thể dung thẳng TRISx, POTRx để viết code
#include<16F877A.h>
#include<def_877a.h>
#fuses NOWDT,PUT,HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use fast_io(b)
int8 sck,slx,bienxoay,bienluu,giatri;
main()
{
trisb=0;
while(true)
{
sck=8;
bienluu=0;
portb=0;
delay_ms(100);
while(sck>0)
{
bienxoay=1;
slx=sck;
while(slx>0)
{
giatri=bienluu|bienxoay;
portb=giatri;
delay_ms(100);
bienxoay=bienxoay<<1;
slx--;
}
bienluu=giatri;
sck--;
}
}
}
nhưng đoạn code này thì em dùng thẳng trisx, portx thì không được nhung dùng lệnh set_tris_x(gia tri), set_port_x(gia tri) thi được em nghi đó là do khai báo lúc đầu
#include "E:\PIC\main.h"
#include <16f877a.h>
#include <def_877a.h>
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)

void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_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);
setup_vref(FALSE);

// TODO: USER CODE!!
TRISB = 0x00; // Tat ca PORTB deu la cong xuat du lieu
PORTB = 0xFF; // Tat het cac LED
While(1)
{
PORTB = 0; // Cho các LED sáng
delay_ms(250); // T.o th.i gian tr. 250ms
PORTB = 0xFF;
delay_ms(250);
}

}

quangvanvo
08-01-2011, 09:30 AM
anh chị ơi giúp khai báo đầu chương trình di mấy anh chị ơi
sao thấy mấy anh chị viết code đều dùng thẳng TRISX, PORTX để viết code thì được nhưng em copy vào chương trình thì nó luôn báo lỗi nhưng khi em thay băng SET_TRIS_X(GIA TRI), SET_PORT_X(GIA TRI) thì lại được.
còn việt khai báo lúc đằu thì khai báo này thì 2dòng giữa 2dòng @ thì được

@@@@@@@@@@@@@@
#include<16F877A.h>
#include<def_877a.h>
@@@@@@@@@@@@@@@
#fuses NOWDT,PUT,HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use fast_io(b)
int8 sck,slx,bienxoay,bienluu,giatri;


nhưng trong khai báo này thì 2 dòng nay luôn báo lỗi khi bỏ nó thì dich được

#include "E:\PIC\main.h"
@@@@@@@@@@@@@@
#include <16f877a.h>
#include <def_877a.h>
@@@@@@@@@@@@@@@@@@
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)

dung565
09-01-2012, 01:30 PM
doạn core của mình như này


/////////////////////////// Nguyen Thanh Tuan //////////////////////////////
/////////////////////////// TU LAP Mobile //////////////////////////////
/////////////////////////// 82/6, duong 26/3, p.Binh Hung Hoa, q.Binh Tan, Tp.HCM //////////////////////////////
/////////////////////////// 0946 357 994 - 0946 357 995 //////////////////////////////
#include "D:\thanhtuan o D\main.h"
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
void main()
{
int a,t;
while (1)
{
a=0;
while (a<12) // xoay xuoi
{
a++;
output_low (GP5);
output_high (GP0);
delay_ms (80);
output_low (GP0);
output_high (GP1);
delay_ms (80);
output_low (GP1);
output_high (GP2);
delay_ms (80);
output_low (GP2);
output_high (GP4);
delay_ms (80);
output_low (GP4);
output_high (GP5);
delay_ms (80);
}
a=0;
while (a<12) // xoay nguoc
{
a++;
output_low (GP0);
output_high (GP5);
delay_ms (80);
output_low (GP5);
output_high (GP4);
delay_ms (80);
output_low (GP4);
output_high (GP2);
delay_ms (80);
output_low (GP2);
output_high (GP1);
delay_ms (80);
output_low (GP1);
output_high (GP0);
delay_ms (80);
}
t=200;
while (t>20) // ra vao nhanh dan
{
t=t-20;
output_high (GP2);
delay_ms (t);
output_low (GP2);
output_high (GP1);
output_high (GP4);
delay_ms (t);
output_low (GP1);
output_low (GP4);
output_high (GP0);
output_high (GP5);
delay_ms (t);
output_low (GP0);
output_low (GP5);
delay_ms (t);
output_high (GP0);
output_high (GP5);
delay_ms (t);
output_low (GP0);
output_low (GP5);
delay_ms (t);
output_high (GP0);
output_high (GP5);
delay_ms (t);
output_low (GP0);
output_low (GP5);
delay_ms (t);
output_high (GP1);
output_high (GP4);
delay_ms (t);
output_low (GP1);
output_low (GP4);
output_high (GP2);
delay_ms (t);
output_low (GP2);
}
a=0;
while (a<10) // ngoai vao
{
a++;
output_high (GP0);
output_high (GP5);
delay_ms (100);
output_high (GP1);
output_high (GP4);
delay_ms (100);
output_high (GP2);
delay_ms (100);
output_low (GP0);
output_low (GP5);
delay_ms (100);
output_low (GP1);
output_low (GP4);
delay_ms (100);
output_low (GP2);
delay_ms (100);
}
t=400;
while (t>4) // xoay tron nhanh dan
{
t=t-4;
output_high (GP5);
delay_ms (t);
output_low (GP5);
output_high (GP4);
delay_ms (t);
output_low (GP4);
output_high (GP2);
delay_ms (t);
output_low (GP2);
output_high (GP1);
delay_ms (t);
output_low (GP1);
output_high (GP0);
delay_ms (t);
output_low (GP0);
}
a=0;
while (a<10) // chop cheo 1
{
a++;
output_low (GP4);
output_high (GP0);
delay_ms (140);
output_low (GP0);
output_high (GP4);
delay_ms (140);
}
a=0;
while (a<10) // chop cheo 2
{
a++;
output_low (GP1);
output_high (GP0);
delay_ms (140);
output_low (GP0);
output_high (GP4);
delay_ms (140);
output_low (GP4);
output_high (GP5);
delay_ms (140);
output_low (GP5);
output_high (GP1);
delay_ms (140);
}
t=120;
while (t>10) // xuong len nhanh dan
{
t=t-10;
output_high (GP0);
delay_ms (t);
output_low (GP0);
output_high (GP1);
delay_ms (t);
output_low (GP1);
output_high (GP2);
delay_ms (t);
output_low (GP2);
output_high (GP4);
delay_ms (t);
output_low (GP4);
output_high (GP5);
delay_ms (t);
output_low (GP5);
output_high (GP4);
delay_ms (t);
output_low (GP4);
output_high (GP2);
delay_ms (t);
output_low (GP2);
output_high (GP1);
delay_ms (t);
output_low (GP1);
}
a=0;
while (a<20) // 0 5 qua lai
{
a++;
output_high (GP0);
delay_ms (180);
output_high (GP2);
output_low (GP0);
delay_ms (30);
output_high (GP4);
output_low (GP2);
delay_ms (30);
output_high (GP5);
output_low (GP4);
delay_ms (200);
output_high (GP1);
output_low (GP5);
delay_ms (100);
output_low (GP1);
}
t=400;
while (t>10) // chop tat all nhanh dan
{
t=t-10;
output_high (GP0);
output_high (GP1);
output_high (GP2);
output_high (GP4);
output_high (GP5);
delay_ms (t);
output_low (GP0);
output_low (GP1);
output_low (GP2);
output_low (GP4);
output_low (GP5);
delay_ms (t);
}
t=120;
while (t>10) // sang & xoay tron
{
t=t-5;
output_high (GP0);
delay_ms (t);
output_high (GP1);
delay_ms (t);
output_high (GP2);
delay_ms (t);
output_high (GP4);
delay_ms (t);
output_high (GP5);
delay_ms (t);
output_low (GP5);
delay_ms (t);
output_low (GP4);
delay_ms (t);
output_low (GP2);
delay_ms (t);
output_low (GP1);
delay_ms (t);
output_low (GP0);
delay_ms (t);
}
a=0;
while (a<20) // xoay dong tung nac
{
a++;
output_high (GP0);
delay_ms (250);
output_high (GP1);
output_low (GP0);
delay_ms (40);
output_high (GP2);
output_low (GP1);
delay_ms (40);
output_high (GP4);
output_low (GP2);
delay_ms (40);
output_high (GP5);
output_low (GP4);
delay_ms (40);
output_low (GP5);
output_high (GP0);
delay_ms (40);
output_high (GP1);
output_low (GP0);
delay_ms (40);
output_high (GP2);
output_low (GP1);
delay_ms (40);
output_high (GP4);
output_low (GP2);
delay_ms (40);
output_high (GP5);
output_low (GP4);
delay_ms (40);
output_low (GP5);
}
t=120;
while (t>10) // len xuong 1 bong nhanh dan
{
t=t-5;
output_high (GP0);
delay_ms (t);
output_high (GP1);
output_low (GP0);
delay_ms (t);
output_low (GP1);
output_high (GP2);
delay_ms (t);
output_low (GP2);
output_high (GP4);
delay_ms (t);
output_low (GP4);
output_high (GP5);
delay_ms (t);
output_low (GP5);
output_high (GP4);
delay_ms (t);
output_low (GP4);
output_high (GP2);
delay_ms (t);
output_low (GP2);
delay_ms (t);
output_high (GP1);
delay_ms (t);
output_low (GP4);
output_high (GP0);
delay_ms (t);
}
}
}

chạy nữa chừng tối đây thằng ccs nó đứng im lun rồi nó báo lỗi này nè hix

http://nh8.upanh.com/b6.s1.d5/77710ce8825c1965b11571953d784b46_39813158.loi.bmp

em không biết up hình như thế nào đây là lần đầu bị trở ngại này xin pro chỉ giáo e mới vào nghề hix
nếu pro nào biết cách khắc phục dc dùm em đoạn core này e xin tặn cho pro đó 1 bộ vỏ sườn trong xuốt + ic led cho 1202 lun ( sdt e nè 01217951886 ) sms e goi lai liền :)