We made a small project with AT89C51. It is a simple LED show which can be adjusted by external inputs. We used Keil C. the file compiled with no errors and no warnings. The simulator ( Vault information services simulator) worked perfect. However, when we downloaded the file on the chip, the downloading software produced a strange error: "ERROR on line 259" So, what could be the problem? Is it something common?.( Note: the chip is not defective). here is the C source
/* This code is for the "LED SHOW" project.The idea is to generate the required squence by only changing the value of a 32 bit variable which is px in this code. px is an unsigned long int variable. The function led_out reads a 32 bit variable which is pn then splits it into a four 8 bit variables then sends these variables to the four output ports of 8051 microcontroller. The function unit_delay reads one 8 bit variables "d" which is the number of basic delay units. and resultes in delay = basic_delay_unit * d. in this code basic_delay_unit =.05 sec The function show_generator it's function is to generate the show.you can choose the number of leds used in the show by the variable "no_of_leds". and you can control the speed by the variable "delay".and you can choose if the show is inversion or not -means no_of_leds is on and the rest is off or the inversion- . In this code you can choose the required show and it's speed by the input port P3. by using the following truth tables: P3_2 P3_1 P3_0 0 0 0 MIX 0 0 1 One Led 0 1 0 Two Leds 0 1 1 Three Leds 1 0 0 Four Leds in mix show no other controls needed P3_3 0 Normal Show 1 Inversion Show P3_4 0 Normal Show 1 Show and its Inversion & P3_3 is ignored P3_6 P3_5 Delay 0 0 50 mS 0 1 100mS 1 0 150mS 1 1 200mS P3_7 0 Stop 1 Resume any other cases out of truth table will be igonred */ #include <AT89X51.H> //time base is a 16 bit no. the lowest 8 bits are time_base_l //and the highest 8 bits are time_base)_h. //the time base is the inintial value of timer0 to counts from the time base //to 0xFFFF which generates .05 sec period #define time_base_l 0xB0;//lower time base #define time_base_h 0x3C;//higher time base unsigned char time_delay;//no. of basic_delay units used unit_delay() & time0() only //Functions defination void unit_delay(unsigned char d); void led_out(unsigned long int pn); void show_generator(unsigned char no_of_leds,unsigned char delay,bit inversion_enable); void main(void) { unsigned char show_mode,show_speed,count,i; bit inversion,mode_and_inversion; //adjusting the control registers IP=IP|0x02; //set timer interrupt to have highest priority TMOD=TMOD|0x01; //set timer0 into mode 1 IE=130;//enable interrupts inversion=0; while(1){ show_mode=P3 & 0x07; show_speed=((P3 & 0x60)>>5)+1; if(mode_and_inversion) inversion=~inversion; else inversion=P3_3; mode_and_inversion=P3_4; if(show_mode<=4 && show_mode!=0) show_generator(show_mode,show_speed,inversion); while(show_mode==0){ inversion=0; for(count=1;count<=4;count++){ for(i=1;i<=4;i++){ show_generator(i,count,inversion); show_generator(i,count,~inversion); } } } } } void led_out(unsigned long int pn) { unsigned char i[3],c; /*i[n] is an array of four 8 bit elements that the 32 bit variable pn will split into.such that the LS 8 bits of pn will be stored in i[0] and the next 8 bits will be stored in i[1] and so on. and c is a counter vairable used in for loop. */ for(c=0;c<3;c++){ i[c]=(pn >> (c*8));//i[c]= c*8 right shifts } //sending the values of i[n] to output ports P0=i[0]; P1=i[1];