THư viện:
Chương trình chính:
Thư viện viết theo cách của hocavr.com nhưng viết bằng codevision ko chạy. Có ai biết lỗi sửa hộ mình. Thanks!
Code:
#include <delay.h>
#define EN PORTB.2
#define RW PORTB.1
#define RS PORTB.0
#define BF PINB.7
/*#define DATA_O PORTB
#define DATA_I PINB
#define DDR_DATA DDRB
*/
char Read_LCD()
{
char LB,HB;
PORTB|=0xf0;
EN=1;
DDRB&=0x0f;
HB=PINB&0xf0;
EN=0;
EN=1;
LB=PINB&0xf0;
EN=0;
LB=LB>>4;
return(HB|LB);
}
void Write_LCD(unsigned char chr)
{
unsigned char temp,HB,LB;
temp=PORTB&0x0f;
HB=chr&0xf0;
LB=(chr<<4)&0xf0;
PORTB=(HB|temp);
EN=1;
EN=0;
PORTB=(LB|temp);
EN=1;
EN=0;
}
void Wait_LCD()
{
char temp;
while(1)
{
RS=0;
RW=1;
temp=Read_LCD();
temp=temp&0x80;
if (temp==0)
break;
}
RW=0;
DDRB=0xff;
}
void Start_LCD()
{
DDRB=0xff;
PORTB=0xff;
// function set
RW=0;
RS=0;
EN=0;
EN=1;
PORTB.5=1;
EN=0;
Wait_LCD();
Write_LCD(0x28);
Wait_LCD();
//Dispaly control
RS=0;
Write_LCD(0x0e);
Wait_LCD();
//Entry mode set
RS=0;
Write_LCD(0x06);
Wait_LCD();
}
void Home_LCD()
{
RS=0;
Write_LCD(0x02);
Wait_LCD();
}
void Move_LCD(char y,char x)
{
char temp;
temp=64*(y-1)+(x-1)+0x80;
RS=0;
Write_LCD(temp);
Wait_LCD();
}
void Clear_LCD()
{
RS=0;
Write_LCD(0x01);
Wait_LCD();
}
void Putchar_LCD(char chr)
{
RS=1;
Write_LCD(chr);
Wait_LCD();
}
Code:
#include <mega16.h>
#include <LCDG.h>
void main()
{
Start_LCD();
Clear_LCD();
Putchar_LCD('A');
Putchar_LCD('V');
Putchar_LCD('R');
while(1)
{
}
}

Comment