fauzan
Newbie level 3
I need help for my stopwatch project, i have problem to show the time like "02:04.89", the problem is when i start the microcontroller, the program can't display "0" beside "2", it's just show number "2_" when number become tens, it will show... can u fix it? i hope anybody can help me... thanks
this is my program
this is my program
Code:
Chip type : ATmega8535
Program type : Application
AVR Core Clock frequency: 4,000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 128
#include <mega8535.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <stdio.h>
#include <stdlib.h>
unsigned int count=0,kali=0;
unsigned char detik=0, menit=0;
unsigned char cdetik[10],cmenit[10],ccount[10];
// Timer1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer1 value
TCNT1H=0xFF64 >> 256;
TCNT1L=0xFF64 & 0xff;
if(++count==100)
{
count=0;
lcd_clear();
if(++detik==60)
{
detik=0;
lcd_clear();
if(++menit==20)
{
menit=0;
lcd_clear();
}
}
}
kali=0;
itoa(count,ccount);
itoa(detik,cdetik);
itoa(menit,cmenit);
lcd_gotoxy(11,0);
lcd_puts(ccount);
lcd_gotoxy(10,0);
lcd_puts(".");
lcd_gotoxy(8,0);
lcd_puts(cdetik);
lcd_gotoxy(7,0);
lcd_puts(":");
lcd_gotoxy(5,0);
lcd_puts(cmenit);
// Place your code here
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
TCCR1A=0x00;
TCCR1B=0x01;
TCNT1H=0xFF;
TCNT1L=0x64;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
MCUCSR=0x00;
TIMSK=0x04;
ACSR=0x80;
SFIOR=0x00;
// LCD module initialization
lcd_init(16);
// Global enable interrupts
#asm("sei")
while (1)
{
};
};