HiSER привет!
Извини погарячился, сказав что все работает -(
Точнее, секунды считает нормально, минуты тоже, но только до 59 мин.
Затем, как только в переменной t.hour появляется 1 (т.е прошел час),
на индикаторах появляется число 256 (т.е. наш сдвиг влево на 8),
затем 257,258 и т.д. Вообщем каждый час происходит инкремент на 256.
Глянь, пожалуйста, в чем косяк? /*****************************************************
This program was produced by the
CodeWizardAVR V1.25.9 Professional
Project : mega2560_Watch_sim5
Version : 0.05
Date : 04/01/2011
Author : F4CG
Company : F4CG
Comments:
Chip type : ATmega2560
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 2048
*****************************************************/
#include <mega2560.h>
#include <mega2560_Watch_sim5.h>
#include <delay.h>
/* char not_leap(void);
char not_leap(void) //check for leap year
{
if (!(t.year%100))
return (char)(t.year%400);
else
return (char)(t.year%4);
} end of leap() */
typedef struct
{
unsigned char second; //enter the current time, date, month, and year
unsigned char minute;
unsigned char hour;
//unsigned char date;
//unsigned char month;
//unsigned int year;
}time;
time t;
flash unsigned char codes[10] = {0x05,0xdd,0x46,0x54,0x9c,0x34,0x24,0x5d,0x04,0x14};
static unsigned char data[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static unsigned int x = 0;
/* #pragma warn-
unsigned int b2i(unsigned char a,unsigned char b)
{
#asm
ld r31,y
ldd r30,y+1
#endasm
}
#pragma warn+*/
void convert_data (unsigned int x)
{
unsigned int temp,result;
temp = x;
result = temp/1000; //Calculate 1000-s
data[4]= codes[result];
temp = temp - result*1000;
result = temp/100; //Calculate 100-s
data[5]= codes[result];
temp = temp - result*100;
result = temp/10; //Calculaate 10-s
data[6]= codes[result];
temp = temp - result*10;
data[7]= codes[temp]; //Calculate 1-s
}//end of convert_data()
// Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer 1 value
TCNT1H=0xE1;//E1
TCNT1L=0x7B;//7B
// Place your code here
//PORTC.2 = 1;
if (++t.second==60) //keep track of time, date, month, and year
{
t.second=0;
if (++t.minute==60)
{
t.minute=0;
if (++t.hour==24)
{
t.hour=0;
}
}
}//end if
x=((unsigned int)t.hour<<8)|t.minute;/////////////
//x = b2i(t.minute,t.hour);
}//end of interrupt(1)
// Timer 3 overflow interrupt service routine
interrupt [TIM3_OVF] void timer3_ovf_isr(void)
{
// Reinitialize Timer 3 value
TCNT3H=0xFB;//FB
TCNT3L=0xFB;//FB
// Place your code here
static unsigned char counter = 4;
PORTJ = 0x00;
PORTC = ~data[counter];
delay_us(150);//150us
if (counter == 4) PORTJ|=(1<<ANOD1);
if (counter == 5) PORTJ|=(1<<ANOD2);
if (counter == 6) PORTJ|=(1<<ANOD3);
if (counter == 7) PORTJ|=(1<<ANOD4);
counter++;
if (counter == 8) counter =4;
}//end of interrupt(3)
// Declare your global variables here
int main(void)
{
// Declare your local variables here
micro_init();
delay_ms(300);//300ms
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
convert_data(x); //Convert data to codes
delay_ms(5);//5ms
};//end while()
return 1;
}//end main
Симулирую в Протэусе 7.5
Спасибо!