#include <18f4520.h>
#include <string.h>
#fuses XT, NOWDT, NOPROTECT, NOBROWNOUT, NOLVP, NOPUT, NOWRT, NODEBUG, NOCPD
#use delay(clock=20M)
void lcd_putc(unsigned char c);
void lcd_command(unsigned char c);
void lcd_init();
void lcd_clear(void);
void lcd_position(unsigned char x,unsigned char y);
void lcd_printf(char *a);
void one_wire(unsigned char data);
void main()
{
set_tris_b(0x00);
lcd_init();
while(TRUE)
{
lcd_printf("Deneme");
}
}
void lcd_putc(unsigned char c )
{
unsigned char data;
data = 0x00;
data |=0x50;
one_wire(data);
data |= ((c & 0xF0)>>4);
one_wire(data);
data &= 0x1F;
one_wire(data);
delay_us(100);
data = 0x00;
data |= 0x50;
one_wire(data);
data |= (((c & 0x0F) << 4) >> 4);
one_wire(data);
data &= 0x1F;
one_wire(data);
delay_us(100);
}
void lcd_command(unsigned char c)
{
unsigned char data;
data = 0x00;
data |=0x40;
one_wire(data);
data |= ((c & 0xF0)>>4);
one_wire(data);
data &= 0x0F;
one_wire(data);
delay_us(100);
data = 0x00;
data |= 0x40;
one_wire(data);
data |= (((c & 0x0F) << 4) >> 4);
one_wire(data);
data &= 0x0F;
one_wire(data);
delay_us(100);
}
void lcd_init()
{
one_wire(0);
delay_ms(15);
lcd_command(2);
delay_ms(2);
lcd_command(40);
lcd_command(6);
lcd_command(12);
lcd_clear();
lcd_command(128);
}
void lcd_clear(void)
{
lcd_command(0x1);
delay_ms(2);
}
void lcd_position(unsigned char x,unsigned char y)
{
if(x==1)
lcd_command(0x80+((y-1)%20));
else
lcd_command(0xC0+((y-1)%20));
}
void lcd_printf(char *a)
{
delay_us(100);
while(*a)
{
lcd_putc(*a++);
}
}
void one_wire(unsigned char data)
{
char i;
output_high(pin_b0);
for(i=0;i < 8;i++)
{
if((data<<(i))&0x80)
{
output_low(pin_b0);
//delay_us(1);
output_high(pin_b0);
}
else
{
output_low(pin_b0);
delay_us(15);
output_high(pin_b0);
delay_us(30);
}
}
output_low(pin_b0);
delay_us(210);
output_high(pin_b0);
delay_us(300);
}