سلام
من تازه دارم codevision کار می کنم اما توی این برنامه که فرستادم قسمتی که خط کشیدم error زیر پدیدار می شه
'}' missing
لطفا اشکالشو بگین!!!!!!!!!!!!!!!!!!!!!! :cry2:
Chip type : ATmega16
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*********************************************/
#include <mega16.h>
#include <delay.h>
#include <stdio.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x1B
.equ __sda_bit=0
.equ __scl_bit=1
#endasm
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15
#endasm
#include <lcd.h>
// Declare your global variables here
/*............*/
struct day_structure {char d[4];}daysofweek[7]=[["Sun"],["Mon"],["Tue"],["Wed"],["Thu"],["Fri"],["Sat"]];
hour,minute,second;
char lcd1[20],lcd2[20];
unsigned char year,month,day;
/*............*/
unsigned char key,keystatus;
//////////calculating day of week////////////////
#define OK 1
#define Error 8
flash unsigned char Table[13]={0,0,3,3,6,1,4,6,2,5,0,3,5};
/************************************************
*IsLeapYear
*Return a '1' if the input is a leap year.Else return a '0'
*
*Input variable:16Bit unsigned Int
*Output Varible:'1' if is a leap year, else '0'.
****************************/
char IsLeapYear(int Year)
{
Year=Year&0x0003;
if(Year==0)
return 1;
else
return 0;
}
/************************************************
*CheckValidInput
*Return a '1' if the input is within the required range.Else
*return a '0'.
*
*Input Variable : 16Bit Unsigned Int
*Output Varible : '1' if input ranges between 1990 & 2099 inclusively
************************************************/
char CheckValidInput(unsigned int Input)
{
if(Input>=1990 && Input<=2099 )
return OK;
else
return !OK;
}
/*********************************************
*GetDayofWeek
*This routin calculate the Day(Sunday,Monday,...Saturday) of
*week when a Date(year,Month,Day) is given.
*Input : Year,Month and Day which in this routin is used
*as global variable.
*Output Variable: 0 to 6(which correspond to Sunday to saturday
*respectively) if the input is acceptable, else a value 8 is return
*********************************************/
char GetDayofWeek(unsigned char CurrentYear,unsigned char Month,unsigned char Day)
{
unsigned int TempYear;
unsigned char AccValue;
if(CheckValidInput(CurrentYear+2000)!=OK)/* Return Error if input not Valid*/
return Error;
TempYear= 1990;/*Comparation start with year 1990*/
AccValue= 0;/*Init AccValue to 0*/
/* if TempYear is a leap year AccValue +2, else AccValue+1 */
while(TempYear!= (CurrentYear+2000))
{
AccValue++;
if(IsLeapYear(TempYear))
AccValue++;
TempYear++;
}
if(Month > 2)
{
if(IsLeapYear(TempYear)==1)
AccValue++;
}
AccValue += Table[Month];
AccValue += Day;
AccValue= AccValue%7;
return (AccValue);
}
/************************************************** ******/
flash unsigned char shmtable[6][12]={
{11,10,10,9,9,9,8,9,9,10,11,9},
{20,20,21,21,22,22,22,22,21,21,20,19},
{11,10,10,9,9,9,8,9,9,10,11,10},
{20,20,21,21,22,22,22,22,21,21,20,19},
{12,11,11,10,10,10,9,10,10,11,12,10},
{19,19,20,20,21,21,21,21,20,20,19,18}};
flash unsigned char miltable[6][12]={
{20,19,19,19,20,20,21,21,21,21,20,20},
{10,11,10,12,11,11,10,10,10,9,10,10},
{19,18,20,20,21,21,22,22,22,22,21,21},
{11,12,10,11,10,10,9,9,9,8,9,9},
{20,19,20,20,21,21,22,22,22,22,21,21},
{10,11,9,11,10,10,9,9,9,8,9,9}};
struct date{
unsigned char day;
unsigned char month;
unsigned char year;
};
struct date shmdate,mildate;
/************************************************** *********************/
void miltoshmcv(unsigned char ym,unsigned char mm,unsigned char dm)
{
unsigned char k,t1,t2;
k=ym%4 ;
if(k==3)
k=2;
k*=2;
t1=miltable[k][mm-1];
t2=miltable[k+1][mm-1];
if(mm<3 || (mm==3 && dm<=miltable[k][mm-1]))
shmdate.year = ym + 78;
else
shmdate.year = ym + 79;
if(dm<=t1)
{
shmdate.day=dm+t2;
shmdate.month=(mm+8)%12+1;
}
else
{
shmdate.day=dm-t1;
shmdate.month=(mm+9)%12+1;
}
}
/************************************************** *******/
void shmtomilcv(unsigned char ys ,unsigned char ms, unsigned char ds)
{
unsigned char k,t1,t2;
k= ys%4;
if(k == 0)
k=2;
else
k = k + k;
t1=shmtable[k - 2][ms-1];
t2= shmtable[k-1][ms-1];
if(ms<10 || (ms==10 && ds <= shmtable[k-2][ms-1]))
mildate.year = ys - 79;
else
mildate.year = ys - 78;
if(ds <= t1)
{
mildate.day = ds + t2;
mildate.month = (ms + 1)%12+1;
}
else
{
mildate.day= ds - t1;
mildate.month= (ms + 2)%12+1;
}
}
void main(void)
{
// Declare your local variables here
unsigned char key,kaystatus;
// Input/Output Ports initialization
// Port A initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=P State1=P State2=P State3=P State4=P State5=P State6=P State7=P
PORTB=0xFF;
DDRB=0x00;
// Port C initialization
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out
// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0
PORTC=0x00;
DDRC=0xFF;
// Port D initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
GICR|=0x00;
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
SFIOR=0x00;
// I2C Bus initialization
i2c_init();
// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: On
// Square wave frequency: 1Hz
rtc_init(0,1,0);
// LCD module initialization
lcd_init(20);
while (1)
{
// Place your code here
rtc_get_time(&hour,&minute,&second);
rtc_get_date(&day,&month,&year);
key=PINB & 0b00111111;
if(key!=keystatus)
{
if(key!=0b00111111)
{
if(key==0x3E) //if key 1 pressed set the year
{
year++;
if(year==100)
year=0;
}
if(key==0x3D) //if key 2 pressed set the month
{
month++;
if(month==13)
month=1;
}
if(key==0x3B) //if key 3 pressed set the day
{
day++;
if(day==32)
day=1;
}
if(key==0x37) //if key 4 pressed set the hour
{
hour++;
if(hour==24)
hour=0;
}
if(key==0x2F) //if key 5 pressed set the minute
{
minute++;
if(minute==60)
minute=0;
}
if(key==0x1F) //if key 6 pressed set the second
{
second++;
if(second==60)
second=0;
}
rtc_set_time(hour,minute,second);
rtc_set_date(day,month,year);
keystatus=key;
}else
keystatus=0b00111111;
}
miltoshmcv(year,month,day);
sprintf(lcd1,"20%02u/%02u/%02u/%02u/%02u/%02u/%",
year,month,day,shmdate.year,shmdate.month,shmdate. day);
sprintf(lcd2,"",daysofweek[GetDayofWeek(year,month,day)].d,hour,minute,second);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(lcd1);
lcd_gotoxy(0,1);
lcd_puts(lcd2);
delay_ms(100);
};
}
من تازه دارم codevision کار می کنم اما توی این برنامه که فرستادم قسمتی که خط کشیدم error زیر پدیدار می شه
'}' missing
لطفا اشکالشو بگین!!!!!!!!!!!!!!!!!!!!!! :cry2:
Chip type : ATmega16
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*********************************************/
#include <mega16.h>
#include <delay.h>
#include <stdio.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x1B
.equ __sda_bit=0
.equ __scl_bit=1
#endasm
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15
#endasm
#include <lcd.h>
// Declare your global variables here
/*............*/
struct day_structure {char d[4];}daysofweek[7]=[["Sun"],["Mon"],["Tue"],["Wed"],["Thu"],["Fri"],["Sat"]];
hour,minute,second;
char lcd1[20],lcd2[20];
unsigned char year,month,day;
/*............*/
unsigned char key,keystatus;
//////////calculating day of week////////////////
#define OK 1
#define Error 8
flash unsigned char Table[13]={0,0,3,3,6,1,4,6,2,5,0,3,5};
/************************************************
*IsLeapYear
*Return a '1' if the input is a leap year.Else return a '0'
*
*Input variable:16Bit unsigned Int
*Output Varible:'1' if is a leap year, else '0'.
****************************/
char IsLeapYear(int Year)
{
Year=Year&0x0003;
if(Year==0)
return 1;
else
return 0;
}
/************************************************
*CheckValidInput
*Return a '1' if the input is within the required range.Else
*return a '0'.
*
*Input Variable : 16Bit Unsigned Int
*Output Varible : '1' if input ranges between 1990 & 2099 inclusively
************************************************/
char CheckValidInput(unsigned int Input)
{
if(Input>=1990 && Input<=2099 )
return OK;
else
return !OK;
}
/*********************************************
*GetDayofWeek
*This routin calculate the Day(Sunday,Monday,...Saturday) of
*week when a Date(year,Month,Day) is given.
*Input : Year,Month and Day which in this routin is used
*as global variable.
*Output Variable: 0 to 6(which correspond to Sunday to saturday
*respectively) if the input is acceptable, else a value 8 is return
*********************************************/
char GetDayofWeek(unsigned char CurrentYear,unsigned char Month,unsigned char Day)
{
unsigned int TempYear;
unsigned char AccValue;
if(CheckValidInput(CurrentYear+2000)!=OK)/* Return Error if input not Valid*/
return Error;
TempYear= 1990;/*Comparation start with year 1990*/
AccValue= 0;/*Init AccValue to 0*/
/* if TempYear is a leap year AccValue +2, else AccValue+1 */
while(TempYear!= (CurrentYear+2000))
{
AccValue++;
if(IsLeapYear(TempYear))
AccValue++;
TempYear++;
}
if(Month > 2)
{
if(IsLeapYear(TempYear)==1)
AccValue++;
}
AccValue += Table[Month];
AccValue += Day;
AccValue= AccValue%7;
return (AccValue);
}
/************************************************** ******/
flash unsigned char shmtable[6][12]={
{11,10,10,9,9,9,8,9,9,10,11,9},
{20,20,21,21,22,22,22,22,21,21,20,19},
{11,10,10,9,9,9,8,9,9,10,11,10},
{20,20,21,21,22,22,22,22,21,21,20,19},
{12,11,11,10,10,10,9,10,10,11,12,10},
{19,19,20,20,21,21,21,21,20,20,19,18}};
flash unsigned char miltable[6][12]={
{20,19,19,19,20,20,21,21,21,21,20,20},
{10,11,10,12,11,11,10,10,10,9,10,10},
{19,18,20,20,21,21,22,22,22,22,21,21},
{11,12,10,11,10,10,9,9,9,8,9,9},
{20,19,20,20,21,21,22,22,22,22,21,21},
{10,11,9,11,10,10,9,9,9,8,9,9}};
struct date{
unsigned char day;
unsigned char month;
unsigned char year;
};
struct date shmdate,mildate;
/************************************************** *********************/
void miltoshmcv(unsigned char ym,unsigned char mm,unsigned char dm)
{
unsigned char k,t1,t2;
k=ym%4 ;
if(k==3)
k=2;
k*=2;
t1=miltable[k][mm-1];
t2=miltable[k+1][mm-1];
if(mm<3 || (mm==3 && dm<=miltable[k][mm-1]))
shmdate.year = ym + 78;
else
shmdate.year = ym + 79;
if(dm<=t1)
{
shmdate.day=dm+t2;
shmdate.month=(mm+8)%12+1;
}
else
{
shmdate.day=dm-t1;
shmdate.month=(mm+9)%12+1;
}
}
/************************************************** *******/
void shmtomilcv(unsigned char ys ,unsigned char ms, unsigned char ds)
{
unsigned char k,t1,t2;
k= ys%4;
if(k == 0)
k=2;
else
k = k + k;
t1=shmtable[k - 2][ms-1];
t2= shmtable[k-1][ms-1];
if(ms<10 || (ms==10 && ds <= shmtable[k-2][ms-1]))
mildate.year = ys - 79;
else
mildate.year = ys - 78;
if(ds <= t1)
{
mildate.day = ds + t2;
mildate.month = (ms + 1)%12+1;
}
else
{
mildate.day= ds - t1;
mildate.month= (ms + 2)%12+1;
}
}
void main(void)
{
// Declare your local variables here
unsigned char key,kaystatus;
// Input/Output Ports initialization
// Port A initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=P State1=P State2=P State3=P State4=P State5=P State6=P State7=P
PORTB=0xFF;
DDRB=0x00;
// Port C initialization
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out
// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0
PORTC=0x00;
DDRC=0xFF;
// Port D initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
GICR|=0x00;
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
SFIOR=0x00;
// I2C Bus initialization
i2c_init();
// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: On
// Square wave frequency: 1Hz
rtc_init(0,1,0);
// LCD module initialization
lcd_init(20);
while (1)
{
// Place your code here
rtc_get_time(&hour,&minute,&second);
rtc_get_date(&day,&month,&year);
key=PINB & 0b00111111;
if(key!=keystatus)
{
if(key!=0b00111111)
{
if(key==0x3E) //if key 1 pressed set the year
{
year++;
if(year==100)
year=0;
}
if(key==0x3D) //if key 2 pressed set the month
{
month++;
if(month==13)
month=1;
}
if(key==0x3B) //if key 3 pressed set the day
{
day++;
if(day==32)
day=1;
}
if(key==0x37) //if key 4 pressed set the hour
{
hour++;
if(hour==24)
hour=0;
}
if(key==0x2F) //if key 5 pressed set the minute
{
minute++;
if(minute==60)
minute=0;
}
if(key==0x1F) //if key 6 pressed set the second
{
second++;
if(second==60)
second=0;
}
rtc_set_time(hour,minute,second);
rtc_set_date(day,month,year);
keystatus=key;
}else
keystatus=0b00111111;
}
miltoshmcv(year,month,day);
sprintf(lcd1,"20%02u/%02u/%02u/%02u/%02u/%02u/%",
year,month,day,shmdate.year,shmdate.month,shmdate. day);
sprintf(lcd2,"",daysofweek[GetDayofWeek(year,month,day)].d,hour,minute,second);
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(lcd1);
lcd_gotoxy(0,1);
lcd_puts(lcd2);
delay_ms(100);
};
}
دیدگاه