#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);
void print_number(int);
int a=0,b=0,c=0,d=0,v,i;
unsigned char lcd_buf[17]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void main()
{
T1CON=0X18;
//TMR1H=0X3C;
//TMR1L=0xB0;
TMR1=15536;
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);
i=TMR1H;
//v=TMR1-0x3cb0;
void print_number(unsigned int i)
{
char u = 0;
unsigned char lcd_buf[16];
while(i) {
lcd_buf[u++] = (i % 10 + '0');
i /= 10;
}
while(u) {
send_data(lcd_buf[--u]);
}
}
// a=v/16;
// d=v%16;
// v=v/10;
// b=v%10;
// v=v/10;
// c=v%10;
// send_data(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++);
}