magvi
Member
just wanna share this. i got it working but the problem is that its not *that* precise, but its okay for a start, i guess.. 
the code
View attachment 65753
real time pic:-
View attachment 65751
the code
Code:
#define F_CPU 8000000UL
#include <avr/interrupt.h>
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
#include <stdlib.h>
#include<avr/io.h>
#include<util/delay.h>
#define rs PB0
#define en PB2
short val,val1,i;
unsigned int presc;
char a[10];
char ff[5] = {'F','r','e','q',':'};
void lcddata(char dataout);
void lcdcmd(char cmdout);
void dis_data(char data_value);
void dis_cmd(char cmd_value);
void lcd_init() ;
int main()
{
DDRD = 0x02;
DDRB =0xff;
//counter1 initialization
TIMSK |= 1<<TICIE1;
//TCCR1B |=
TCCR1B |=(1<<ICES1)|(1 << CS12) | (1 << CS11) | (1 << CS10);
//counter 0 initialization
TIMSK |= (1<<TOIE0);
TCCR0 = (1<<CS02) | (1<<CS00);
_delay_ms(50); // delay of 50 mili seconds
lcd_init(); // fuction for intialize
sei();
while(1)
{
/* switch (presc)
{
case 1024:
TCCR0 = (1<<CS02) | (1<<CS00);
case 256:
TCCR0 = (1<<CS02);
case 64:
TCCR0 = (1<<CS01) | (1<<CS00);
case 8:
TCCR0 = (1<<CS01) ;
case 1:
TCCR0 = (1<<CS00);
default :
TCCR0 = (1<<CS02) | (1<<CS00);
}*/
}
return 0;
}
ISR(TIMER0_OVF_vect)
{
val =TCNT1;
TCNT1=0x00;
TCNT0=0X00;
TIFR =0x00;
val =(val/19.912)*100;
itoa(val,a,10);
for(i=0;i<=5;i++)
{
dis_data(ff[i]);
}
for(i=0;i<=10;i++)
{
dis_data(a[i]);
}
_delay_ms(100);
}
void lcd_init() // fuction for intialize
{
dis_cmd(0x83);
dis_cmd(0x02); // to initialize LCD in 4-bit mode.
dis_cmd(0x28); //to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
dis_cmd(0x0C);
dis_cmd(0x06);
dis_cmd(0x83);
dis_cmd(0x01);
}
void dis_cmd(char cmd_value)
{
char cmd_value1;
cmd_value1 = cmd_value & 0xF0; //mask lower nibble because PA4-PA7 pins are used.
lcdcmd(cmd_value1); // send to LCD
cmd_value1 = ((cmd_value<<4) & 0xF0); //shift 4-bit and mask
lcdcmd(cmd_value1); // send to LCD
}
void dis_data(char data_value)
{
char data_value1;
data_value1=data_value&0xF0;
lcddata(data_value1);
data_value1=((data_value<<4)&0xF0);
lcddata(data_value1);
}
void lcdcmd(char cmdout)
{
PORTB=cmdout;
PORTB&=~(1<<rs);
PORTB|=(1<<en);
_delay_ms(1);
PORTB&=~(1<<en);
}
void lcddata(char dataout)
{
PORTB=dataout;
PORTB|=(1<<rs);
PORTB|=(1<<en);
_delay_ms(1);
PORTB&=~(1<<en);
}
proteus simulation :-
real time pic:-
View attachment 65751
Last edited: