Some Errors in Hitech C compiler

Status
Not open for further replies.

ucsam

Advanced Member level 4
Joined
Oct 12, 2010
Messages
119
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
kathmandu,nepal
Visit site
Activity points
2,058
Namaste,

Hi, everyone its been a long time since i have not posted in this site. Well, here i am with my mystery for you guys to solve. I am writing code for a gadget that would show respective data with time and date. But i am having a long list of error. Please try to help me out in this.


This is not the MAIN code. Its just a part of it. But this is the part where the error shows up.

File name: SBFX.c
Code:
/* Battery image contant data */
#define lunchTimeIndex 'L'
#define homeTimeIndex 'H'
#define notApplicable 'N'

int batteryLevel=0;


char dayMon[8];
char dayTue[8];
char dayWed[8];
char dayThu[8];
char dayFri[8];



const char empty[8] = {14,27,17,17,17,17,31,31};
const char twentyPercent[8] = {14,27,17,17,17,31,31,31};
const char fourtyPercent[8] = {14,27,17,17,31,31,31,31};
const char sixtyPercent[8] = {14,27,17,31,31,31,31,31};
const char eightyPercent[8] = {14,27,31,31,31,31,31,31};
const char hundredPercent[8] = {14,31,31,31,31,31,31,31};

// Subject constant
const char physics[]="Physics";
const char math[]="Math";
const char english[]="English";
const char chemistry[]="Chemistry";
const char business[]="Business";
const char economics[]="Economics";
const char biology[]="Biology";
const char nepali[]="Nepali";
const char sca[]="SCA";
const char anthro[]="Anthropolgy";
const char ess[]="ESS";
char tok[]="TOK";
const char cas[]="CAS";
const char french[]="French";
const char spanish[]="Spanish";
const char subjectError[]="Subject error!!";
const char subjectSet[]="Done!";

//Month constants
const char jan[]="Jan ";
const char feb[]="Feb ";
const char march[]="March ";
const char april[]="April ";
const char may[]="May ";
const char june[]="June ";
const char july[]="July ";
const char august[]="Aug ";
const char september[]="Sept ";
const char october[]="Oct ";
const char november[]="Nov ";
const char december[]="Dec ";
const char monthError[]="MM E! ";

// day constants

const char sunday[]="Sunday";
const char monday[]="Monday";
const char tuesday[]="Tueday";
const char wednesday[]="Wednesday";
const char thursday[]="Thursday";
const char friday[]="Friday";
const char saturday[]="Saturday";
const char errorDay[]="Day error!";
const char whatDay[]="What day?";
const char whday[]="Day : ";
 char block[] = "B:";


const char timeFormat[]="HH:MM:SS";
const char yearFormat[]="YYYY-MM-DD";
 char yearInitials[]="20";







	unsigned char time_data[] = "00:00:00";
	unsigned char I2CData[7];
// prototype defination 

void batteryLevelCreator(void);
void batteryLeveldisplay(void);
void append(char to[],const char from[]);
void whatSubject(char number,char *string);

void editThisday(char);
/* subjects index data
1. Physics 
2. Math
3. English 
4. Chemistry
5. Nepali
6. SCA
7. ESS
8. Biology
9. TOK
10. CAS
11. French
12. Spanish
13. Business and Managment
14. Economics
*/
void append(char to[],const char from[]){
char i;
for(i=0;from[i]!='\0';i++)
to[i]=from[i];
to[i] = '\0';
}

void whatSubject(char number,char *string){ // string size should be greater than 9
switch(number){
case 1:
append(string,physics);
break;
case 2:
append(string,math);
break;
case 3:
append(string,english);
break;
case 4:
append(string,chemistry);
break;
case 5:
append(string,nepali);
break;
case 6:
append(string,sca);
break;
case 7:
append(string,ess);
break;
case 8:
append(string,biology);
break;
case 9:
append(string,tok);
break;
case 10:
append(string,cas);
break;
case 11:
append(string,french);
break;
case 12:
append(string,spanish);
break;
case 13:
append(string,business);
break;
case 14:
append(string,economics);
break;
case 15:
append(string,anthro);
break;
default:
append(string,subjectError);
break;
}
}

void monthName(unsigned char *monthName,char month){
switch(month){
case 1:
append(monthName,jan);
break;
case 2:
append(monthName,feb);
break;
case 3:
append(monthName,march);
break;
case 4:
append(monthName,april);
break;
case 5:
append(monthName,may);
break;
case 6:
append(monthName,june);
break;
case 7:
append(monthName,july);
break;
case 8:
append(monthName,august);
break;
case 9:
append(monthName,september);
break;
case 10:
append(monthName,october);
break;
case 11:
append(monthName,november);
break;
case 12:
append(monthName,december);
break;
default:
append(monthName,monthError);
}
}


char whichBlock(unsigned short hour,unsigned short min){
float time;
char index;
time = hour + (min/60);
if(time>=7.75 && time<=8.75)  // 1st block - 7:45 till 8: 45
index=1;
else if(time>8.7 && time<=9.6) // 2nd block - 8:45 till 9:35 (5min break)
index=2;
else if(time>9.6 && time<=10.4) // 3rd block - 9:35 till 10:25 (5min break)
index=3;
else if(time>10.4 && time<=11.5) // 4th block - 10:25 till 11:30 (5min break)
index=4;
else if(time>11.5 && time<=12.2) // Lunch - 11:30 till 12:10
index =lunchTimeIndex;
else if(time>12.2 && time<=12.9) // 5th block - 12:10 till 12:55 (5min break)
index=5;
else if(time>12.9 && time<=13.7) // 6th block - 12:55 till 13:45 (5min break)
index=6;
else if(time>13.7 && time<=14.6) // 7th block - 13:45 to 14:35 (5min break)
index=7;
else if(time>14.6 && time<=14.5) // 7th block - 14:40 to 15:25 (5min break)
index=7;
else if(time>14.583333 && time<=15.416667) // 8th block - 14:35 to 15:25 (5min break)
index=7;
else if(time>15.416667 && time <17.5)
index=homeTimeIndex;  // home time :D
else 
index=notApplicable;
return index;
}



void batteryLevelCreator(void){
     char i;
    LCD_Write(64,0);
    for (i = 0; i<=7; i++)
    LCD_Write(empty[i],1);			
    LCD_Write(72,0);
    for (i = 0; i<=7; i++)
    LCD_Write(twentyPercent[i],1);
    LCD_Write(80,0);
    for (i = 0; i<=7; i++)
    LCD_Write(fourtyPercent[i],1);
    LCD_Write(88,0);
    for (i = 0; i<=7; i++)
    LCD_Write(sixtyPercent[i],1);
    LCD_Write(96,0);
    for (i = 0; i<=7; i++)
    LCD_Write(eightyPercent[i],1);
    LCD_Write(104,0);
    for (i = 0; i<=7; i++)
    LCD_Write(hundredPercent[i],1);
    }

void whichDay(unsigned char dayNumber, unsigned char *string){
switch(dayNumber){
case 1:
append(string,sunday);
break;
case 2:
append(string,monday);
break;
case 3:
append(string,tuesday);
break;
case 4:
append(string,wednesday);
break;
case 5:
append(string,thursday);
break;
case 6:
append(string,friday);
break;
case 7:
append(string,saturday);
break;
default: 
append(string,errorDay);
break;


}
}


    void batteryLeveldisplay(void){
    if(batteryLevel<510) // 5.1 V then show Empty sign
    {
    LCD_Write(0,1);
   delay_20ms(10);
   LCD_goto(2,15);
   LCD_Write(' ',1);
   delay_20ms(10);
   LCD_Write(0,1);
   delay_20ms(10);
    }
    else if(batteryLevel>=510 && batteryLevel<530) // greater than 5.1 V but less than 5.3V then show 20%
    LCD_Write(1,1);
    else if(batteryLevel>=530 && batteryLevel<550) // greater than 5.3 V but less than 5.5V then show 40%
    LCD_Write(2,1);
    else if(batteryLevel>=550 && batteryLevel<580) // greater than 5.3 V but less than 5.8V then show 60%
    LCD_Write(3,1);
    else if(batteryLevel>=580 && batteryLevel<600) // greater than 5.8 V but less than 6.0V then show 80%
    LCD_Write(4,1);
    else if(batteryLevel>=600) // greater than 6.0V hen show 100%
    LCD_Write(5,1);
    }
void EditDisplayTimeAndDate(void){
		unsigned char date_data[] = "2000-00-00";
 		getRTCdata(I2CData);
		BcdToTimeAscii(time_data,I2CData);
		date_data[2]=BCD2UpperCh(I2CData[6]); // year 
		date_data[3]=BCD2LowerCh(I2CData[6]);
		date_data[5]=BCD2UpperCh(I2CData[5]); // month
		date_data[6]=BCD2LowerCh(I2CData[5]);
		date_data[8]=BCD2UpperCh(I2CData[4]); // date
		date_data[9]=BCD2LowerCh(I2CData[4]);
		LCD_cen_string(time_data,1);
		LCD_cen_string(date_data,2);
}
unsigned char BCDtoDEC(char raw){
char temp;
temp = (((raw&0xF0)>>4)*10)+(raw&0x0F);
return temp;
}
void displayTimeAndDate(void){
 		unsigned char month[5];
	
        getRTCdata(I2CData);
		BcdToTimeAscii(time_data,I2CData);
		monthName(month,BCDtoDEC(I2CData[5]));
		LCD_cen_string(time_data,1);	
		LCD_goto(2,2);
		LCD_string(month);
		LCD_num(BCDtoDEC(I2CData[4]));
		LCD_Write(' ',1);
		LCD_string(yearInitials);
		LCD_num(BCDtoDEC(I2CData[6]));
}



void editTimeAndDate(void){
unsigned char modeCount=0,hold=0,limit,temp[7],i;
unsigned char buff[6];
unsigned char dayString[9];
hold=0;
modeCount=0;

/* 
# To enter Edit mode, the following sequence should be done
1. Prese Mode sw
2. Press Power sw
3. Press Ok sw

in time frame of 3 sec

#to change the variable of certain position > Press 'Power' sw to alter the value

#to move from one variable to another > Press 'Mode' sw to change where you want to edit

#to confirm your decision > Press 'Ok' sw, confirming exits you from the edit mode


Note : The control moves as: hours minutes,seconds, month, date, year
*/
LCD_clear();
LCD_cen_string(timeFormat,1);
LCD_cen_string(yearFormat,2);

EditDisplayTimeAndDate();
__delay_ms(20);
//editing time
LCD_Write(0x0E,0);
for(modeCount=0;modeCount<2;modeCount++){
getRTCdata(temp);
hold=BCDtoDEC(temp[2-modeCount]);
do{
LCD_Write((hourAddressOnLCD+modeCount*3),0);
if(!pwrSW){
__delay_ms(20);
__delay_ms(20);
if(!pwrSW){
while(!pwrSW);
if(modeCount==0){
if(hold<23)
hold++;
else
hold=0;
}
else if(modeCount==1 || modeCount==2){
if(hold<59)
hold++;
else
hold=0;
}

LCD_num(hold);
}
}
}
while(modeSW);
while(!modeSW);
buff[1-modeCount]=hold;
}
LCD_Write(1,0);
LCD_Write(0x0C,0);

LCD_cen_string(whatDay,1);
hold=BCDtoDEC(temp[3]);
whichDay(hold,dayString);
do{
whichDay(hold,dayString);
LCD_cen_string(dayString,2);
if(!pwrSW){
__delay_ms(20);
__delay_ms(20);
if(!pwrSW){
if(hold<7)
hold++;
else
hold=1;
clearLine(2);
while(!pwrSW);
}
}
}
while(okSW);
while(!okSW);
buff[2]=hold;
LCD_Write(1,0);
//writeRTCdata(buff); // saving time data
LCD_Write(0x0E,0);
//editing date
EditDisplayTimeAndDate(); 

for(modeCount=0;modeCount<3;modeCount++){
getRTCdata(temp);
hold=BCDtoDEC(temp[6-modeCount]);
do{
LCD_Write(yearAddressOnLCD+modeCount*3,0);
if(!pwrSW){
__delay_ms(20);
__delay_ms(20);
if(!pwrSW){
while(!pwrSW);
if(modeCount==0){
if(hold<=99) // year
hold++;
else
hold=0;
}
else if(modeCount==1){ // month
if(hold<12)
hold++;
else
hold=1;
}
else if(modeCount==2){ // date
if(buff[4]==2 && buff[5]%4==0 ) // Feburary and Leap year
limit=29;
if(buff[4]==2 && buff[5]%4!=0)  // Feb but not leap year
limit=28;
else if(buff[4]==1 || buff[4]==3 ||buff[4]==5 ||buff[4]==7 ||buff[4]==8 ||buff[4]==10 ||buff[4]==12)
limit=31;
else if(buff[4]==4 || buff[4]==6 ||buff[4]==9 || buff[4]==11)
limit=30;

if(hold<limit)
hold++;
else 
hold=1;
}
LCD_num(hold);
}
}
}
while(modeSW);
while(!modeSW);
buff[5-modeCount]=hold;
}
LCD_Write(1,0);
writeRTCdata(buff); // saving date data


}
void editSubject(unsigned char *subjectIndex,char day)
{
unsigned char i=1,j=1,subjectString[9],dayString[9];


LCD_clear();
LCD_Write(0x0C,0);  // cursor off

LCD_string(whday);
whichDay(day,dayString);
LCD_string(dayString);

LCD_goto(2,12);
LCD_string(block);
LCD_num(i); // printing what Block we are in

whatSubject(j,subjectString);

LCD_cen_string(subjectString,2);

for(i=0;i<8;i++){
do{
LCD_goto(2,12);
LCD_string(block);
LCD_num(i+1); // printing what Block we are in
if(!pwrSW){
__delay_ms(20);
__delay_ms(20);
if(!pwrSW){
while(!pwrSW);
if(j<14)
j++;
else
j=1;
clearLine(2);
whatSubject(j,subjectString);
LCD_cen_string(subjectString,2);
}
}
}
while(modeSW);
while(!modeSW);
subjectIndex[i]=j;
}
LCD_clear();
LCD_cen_string(subjectSet,1);
delay_20ms(100);
}


void editThisday(char dayNumber){
switch(dayNumber){
case 2:
editSubject(dayMon,dayNumber);
break;
case 3:
editSubject(dayTue,dayNumber);
break;
case 4:
editSubject(dayWed,dayNumber);
break;
case 5:
editSubject(dayThu,dayNumber);
break;
case 6:
editSubject(dayFri,dayNumber);
break;
default:
editSubject(dayMon,2);
break;
}
}

void showCurrentSub(char *string){
char hour,min,blockNum,SubjectString[9];
LCD_clear();
LCD_Write(0X0C,0);
getRTCdata(I2CData);
hour = BCDtoDEC(I2CData[2]); // find the time right now
min = BCDtoDEC(I2CData[1]);
blockNum = whichBlock(hour,min);
whatSubject(string[blockNum],SubjectString);

LCD_cen_string("Current subject :",1);
LCD_cen_string(SubjectString,2);
delay_20ms(100);
LCD_clear();
delay_20ms(10);
}



void subjectEditing(void){
char dayString[9];
char temp,i;
temp=0;i=0;
LCD_clear();

LCD_Write(0x0C,0);  // cursor off
LCD_cen_string("Subject Editing",1);
delay_20ms(70);
LCD_clear();
LCD_cen_string("Options: ",1);
LCD_cen_string("1. Sequential",2);
do{ // using 'Ok' to signify that you are ok
if(!pwrSW){
delay_20ms(1);
if(!pwrSW){
while(!pwrSW);
i=1;
clearLine(2);
temp++;
if(temp==1){
LCD_cen_string("2. Day Select",2);
}
else if(temp==2){
temp=0;
LCD_cen_string("1. Sequential",2);
}
}
}

}
while(okSW);
while(!okSW);
LCD_clear();
if(temp==2 || (temp==0 && i==0)){
for(temp=2;temp<7;temp++)
editThisday(temp);  // seq
}
else if(temp==1){
temp=2;
LCD_cen_string("Select day :",1);
LCD_cen_string("Monday",2);
do{
if(!pwrSW){
delay_20ms(1);
if(!pwrSW){
while(!pwrSW);
if(temp<6)
temp++;
else 
temp=2;
clearLine(2);
whichDay(temp,dayString);
LCD_cen_string(dayString,2);

}
}
}while(okSW);
while(!okSW);
if(temp!=1 && temp!=7);
 editThisday(temp);
}
}
// With every toggle, the selected subject is stoed in subjectIndex, saved as :
//if subjectIndex[0] = 14 then, the first subject is Economics and so on.. 



void greeting(void){
char i;
LCD_clear();
LCD_Write(0x0c,0);
LCD_cen_string("Usha works.",1);
delay_20ms(50);
LCD_clear();
slow_LCD_cen_string("Subject Reminder",1);
delay_20ms(25);
slow_LCD_string("By Samarpan");
delay_20ms(80);
for(i=0;i<5;i++)
{
LCD_Write(0x1C,0);
delay_20ms(30);
}
for(i=0;i<5;i++)
{
LCD_Write(0x18,0);
delay_20ms(30);
}
delay_20ms(60);
LCD_clear();
}
void displaySubject(void){
char day;
getRTCdata(I2CData);
day = BCDtoDEC(I2CData[3]); // todays day

switch(day){
case 2: // start with monday
showCurrentSub(dayMon);
break;
case 3: // start with monday
showCurrentSub(dayTue);
break;
case 4: // start with monday
showCurrentSub(dayWed);
break;
case 5: // start with monday
showCurrentSub(dayThu);
break;
case 6: // start with monday
showCurrentSub(dayFri);
break;
default :
LCD_clear();
LCD_cen_string("subj retrive error",1);
delay_20ms(20);
LCD_clear();
break;
}
}

 void displayBatteryLevel(void){
LCD_goto(1,15);
batteryLeveldisplay();
}
void screen(char screenNumber){
/* This screen will display once the user presses any of the key after the display is down. This gives the following information
 1. Current date
 2. Current time
*/
switch(screenNumber){
case 0:
greeting();
break;
case 1:
displayTimeAndDate();
 break;
case 2:
 displaySubject();
 break;
case 3:
 displayBatteryLevel();
 break;
default:
displayTimeAndDate();
 break;


}
}


and errors are :


Thank you,
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…