Page 1 of 1

TIMERS -need help

Posted: 25 Nov 2008 20:12
by jcekovic2
I'm using Easy AVR3, mikrobasic for AVR, and having troubles with simple timer application!
i' ve pasted the code below - what it does is simply write seconds and minutes on GLCD(it works but it shouldn't). what i don't understand: how come that with 8 MHz Quartz and a prescaler of 1024 i count 30 times in a second when i should count round 7800? changing clock source in AVRFlashv2 doesn't change anything. Device frequency changes also do nothing(AVRFlash is set to External clock, 8Mhz) Please help, anyone!!

program timer0

dim sec, min, counter as integer
dim ispis as char[20]
dim ispis2 as char[20]

sub procedure sekundar org$16
CLI
inc(counter)
SEI
end sub



main:
sec=0
min=0
counter=0
TIMSK=1
TCCR0=$05
SREG.7=1

Glcd_Init(PORTC, 0, 1, 2, 3, 5, 4, PORTA)
Glcd_Set_Font(font5x8, 5, 8, 32)
Glcd_fill(0)


while TRUE
if counter=30[/b] then
counter=0
sec=sec+1
end if

if sec=60 then
sec=0
min=min+1
end if


inttostr(sec, ispis)
inttostr(min, ispis2)
Glcd_Write_Text("sekunde", 0, 1, 1)
Glcd_Write_Text(ispis, 0, 2, 1)
Glcd_Write_Text("minutice", 0, 3, 1)
Glcd_Write_Text(ispis2, 0, 4, 1)

wend

end.

Posted: 28 Nov 2008 07:15
by jcekovic2
Solved!

My bad...