|
.
.
Untitled
#include <avr/pgmspace.h> #ifndef setb #include "wait.c"
#endif
#ifndef PORT_RS
#define PORT_RS PORTD
#define DDR_RS DDRD
#endif
#ifndef PORT_EN
#define PORT_EN PORTD
#define DDR_EN DDRD
#endif
#ifndef PORT_D4
#define PORT_D4 PORTD
#define PORT_D5 PORTD
#define PORT_D6 PORTD
#define PORT_D7 PORTD
#define DDR_D4 DDRD
#define DDR_D5 DDRD
#define DDR_D6 DDRD
#define DDR_D7 DDRD
#endif
#ifndef RS
#define RS 2
#endif
#ifndef EN
#define EN 3
#endif
#ifndef D4
#define D4 4
#define D5 5
#define D6 6
#define D7 7
#endif
void lcd_ini (void); void lcd_instr(unsigned char ins); void lcd_char (unsigned char dat); void lcd_num3 (unsigned int num,unsigned char znak); void lcd_num2 (unsigned char num,unsigned char znak); void lcd_text (char* text); void lcd_ftext(const char* text); #define lcd_byt(byt) lcd_num3(byt,' ') #define cls() lcd_instr(0x01);wait_ms(3) #define cursor_off() lcd_instr(0x0c) #define cursor_on() lcd_instr(0x0e) #define cursor_blink() lcd_instr(0x0f) #define shift_lcd_left() lcd_instr(0x18) #define shift_lcd_right() lcd_instr(0x1c) #define gotoxy(lin,col) lcd_instr(64*((lin)+1)+((col)-1)) void lcd_num3(unsigned int num,unsigned char znak)
{
unsigned char i;
num%=1000; i=num/100; if(i==0) lcd_char(znak); else {
lcd_char(0x30+i); znak=('0'); }
lcd_num2(num,znak); }
void lcd_num2(unsigned char num,unsigned char znak)
{
unsigned char i;
num%=100; i=num/10; if(i==0) lcd_char(znak); else lcd_char(0x30+i);
lcd_char(0x30+num%10);}
void lcd_text(char* text)
{
unsigned char i=0,temp;
do
{
temp = text[i];
if(temp==0) break; lcd_char(temp);
i++;
}
while(temp>0);
}
void lcd_ftext(const char* text)
{
unsigned char i=0,temp;
do
{
temp =pgm_read_byte(text+i); if(temp==0) break;
lcd_char(temp);
i++;
}
while(temp>0);
}
void len(void) {
setb(PORT_EN,EN);
wait_us(1);
clrb(PORT_EN,EN);
wait_us(50);
}
void write(char c)
{
char temp;
temp = c & 0xf0; if(temp&(1<<4)) setb(PORT_D4,D4); else clrb(PORT_D4,D4);
if(temp&(1<<5)) setb(PORT_D5,D5); else clrb(PORT_D5,D5);
if(temp&(1<<6)) setb(PORT_D6,D6); else clrb(PORT_D6,D6);
if(temp&(1<<7)) setb(PORT_D7,D7); else clrb(PORT_D7,D7);
len();
temp = c & 0x0f; temp <<= 4; if(temp&(1<<4)) setb(PORT_D4,D4); else clrb(PORT_D4,D4);
if(temp&(1<<5)) setb(PORT_D5,D5); else clrb(PORT_D5,D5);
if(temp&(1<<6)) setb(PORT_D6,D6); else clrb(PORT_D6,D6);
if(temp&(1<<7)) setb(PORT_D7,D7); else clrb(PORT_D7,D7);
len();
}
void lcd_char(unsigned char dat)
{
setb(PORT_RS,RS);
write(dat);
}
void lcd_instr(unsigned char ins)
{
clrb(PORT_RS,RS);
write(ins);
}
void lcd_ini(void)
{
setb(DDR_D4,D4);
setb(DDR_D5,D5);
setb(DDR_D6,D6);
setb(DDR_D7,D7);
setb(DDR_RS,RS);
setb(DDR_EN,EN);
clrb(PORT_RS,RS);
clrb(PORT_EN,EN);
wait_ms(16);
setb(PORT_D4,D4);
setb(PORT_D5,D5);
len();
wait_ms(5);
len();
wait_us(6);
len();
clrb(PORT_D4,D4);
len();
lcd_instr(0x28);
lcd_instr(0x06);
lcd_instr(0x0c);
lcd_instr(0x01);
wait_ms(3);
}
|