azarutz
Member level 2
hi, i want to start the timer when a pin high and stop the timer when another pin high and display the count in lcd for that i written a c program in hi-tech c compiler . first i didnt know how to convert hex value to decimal . my program my simulation as follow
in program display function i wrote to display the hex value but it didnt seem correct .
Code:
#include <pic.h>
#define RS RB0
#define RW RB1
#define E RB2
void pic_init(void);
void lcd_init(void);
void delay(int);
void command(char);
void send_data(char);
void display(void);
int a=0,b=0,c=0,d=0,v;
void main()
{
T1CON=0X18;
TMR1H=0X3C;
TMR1L=0xB0;
pic_init();
lcd_init();
while(1)
{
if(RC3==1)
{
TMR1ON=1;
if(RC4==1)
{
TMR1ON=0;
}
}
display();
}
}
void pic_init(void)
{
TRISA=0xff;
PORTA=0x00;
TRISB=0x00;
PORTB=0x00;
TRISD=0x00;
PORTD=0x00;
}
void lcd_init(void)
{
command(0x38);
command(0x01);
command(0x0c);
}
void command(char comm)
{
PORTD=comm;
RS=0; //register select
RW=0;//read or write
E=1; //enable data line
delay(1000);
E=0; //disable data line
delay(1000);
}
void send_data(char data)
{
PORTD=data;
RS=1;
RW=0;
E=1;
delay(1000);
E=0;
delay(1000);
}
void display()
{
command(0x80);
//v=TMR1H;
v=TMR1-0x3cb0;
a=v/10;
d=v%10;
v=v/10;
b=v%10;
v=v/10;
c=v%10;
send_data(0x30+a);
send_data(0x30+b);
send_data(0x30+c);
send_data(0x30+d);
}
void delay(int d)
{
int i;
for(i=0;i<=d;i++);
}