em đang làm hiển thị lcd 8 bít mà sao mãi chưa được, bác nào từng viết lcd 8 bít tìm lỗi sai trong code này em với
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.05.5a Evaluation
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
HP InfoTech, Development Tools for Microcontrollers, C Compilers, In-System Programmers
Project :
Version :
Date : 3/6/2012
Author : Freeware, for evaluation and
non-commercial use only
Company :
Comments:
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega16.h>
#include <delay.h>
#define RS PORTD.2
#define RW PORTD.1
#define E PORTD.1
#define PC PORTC
unsigned char ten[]={"trinh phi hung"};
unsigned char lop[]={"d09dta1"};
int i,j;
void kiemtra(void)
{unsigned char kt;
kt=0x80;
DDRC=0x00;
while((kt&0x80)==0x80)
{ RS=0;
RW=1;
kt=PC;
E=1;
E=0;
delay_us(200);
};
}
void ghilenh(unsigned char lenh)
{ kiemtra();
DDRC=0xFF;
RS=0;
RW=0;
PC= lenh;
E=1;
delay_us(200);
E=0;
}
void ghikitu(unsigned char kitu)
{ kiemtra();
DDRC=0xFF;
RS=1;
RW=0;
PC=kitu;
E=1;
delay_us(200);
E=0;
}
void khoidong(void)
{ ghilenh(0x38);
ghilenh(0x0e);
ghilenh(0x80);
}
void xoalcd(void)
{ ghilenh(0x01);
ghilenh(0x80);
}
unsigned char dongcot[2]={0x80,0xc0};
void gotoxy(unsigned char x,unsigned char y)
{ kiemtra();
ghilenh(dongcot[y]+x);
}
void main(void)
{
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Graphic LCD initialization
// The KS0108 connections are specified in the
// Project|Configure|C Compiler|Libraries|Graphic LCD menu:
// DB0 - PORTC Bit 0
// DB1 - PORTC Bit 1
// DB2 - PORTC Bit 2
// DB3 - PORTC Bit 3
// DB4 - PORTC Bit 4
// DB5 - PORTC Bit 5
// DB6 - PORTC Bit 6
// DB7 - PORTC Bit 7
// E - PORTD Bit 0
// RD /WR - PORTD Bit 1
// RS - PORTD Bit 2
// /RST - PORTB Bit 3
// CS1 - PORTB Bit 4
// CS2 - PORTB Bit 5
khoidong();
xoalcd();
while (1)
{ gotoxy(0,0);
for(i=0;i<15;i++)
ghikitu(ten[i]);
ghilenh(0xc0);
for(j=0;j<8;j++)
ghikitu(lop[j]);
}
}
em sử dụng chức năng chạy từng dòng trong proteus thì thấy nó chỉ lẩn quẩn trong cái hàm con kiemtra() thôi.ai có cách khắc phục thì giúp em với 2 ngày này em điên đầu với cái này lắm ròi
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.05.5a Evaluation
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
HP InfoTech, Development Tools for Microcontrollers, C Compilers, In-System Programmers
Project :
Version :
Date : 3/6/2012
Author : Freeware, for evaluation and
non-commercial use only
Company :
Comments:
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega16.h>
#include <delay.h>
#define RS PORTD.2
#define RW PORTD.1
#define E PORTD.1
#define PC PORTC
unsigned char ten[]={"trinh phi hung"};
unsigned char lop[]={"d09dta1"};
int i,j;
void kiemtra(void)
{unsigned char kt;
kt=0x80;
DDRC=0x00;
while((kt&0x80)==0x80)
{ RS=0;
RW=1;
kt=PC;
E=1;
E=0;
delay_us(200);
};
}
void ghilenh(unsigned char lenh)
{ kiemtra();
DDRC=0xFF;
RS=0;
RW=0;
PC= lenh;
E=1;
delay_us(200);
E=0;
}
void ghikitu(unsigned char kitu)
{ kiemtra();
DDRC=0xFF;
RS=1;
RW=0;
PC=kitu;
E=1;
delay_us(200);
E=0;
}
void khoidong(void)
{ ghilenh(0x38);
ghilenh(0x0e);
ghilenh(0x80);
}
void xoalcd(void)
{ ghilenh(0x01);
ghilenh(0x80);
}
unsigned char dongcot[2]={0x80,0xc0};
void gotoxy(unsigned char x,unsigned char y)
{ kiemtra();
ghilenh(dongcot[y]+x);
}
void main(void)
{
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Graphic LCD initialization
// The KS0108 connections are specified in the
// Project|Configure|C Compiler|Libraries|Graphic LCD menu:
// DB0 - PORTC Bit 0
// DB1 - PORTC Bit 1
// DB2 - PORTC Bit 2
// DB3 - PORTC Bit 3
// DB4 - PORTC Bit 4
// DB5 - PORTC Bit 5
// DB6 - PORTC Bit 6
// DB7 - PORTC Bit 7
// E - PORTD Bit 0
// RD /WR - PORTD Bit 1
// RS - PORTD Bit 2
// /RST - PORTB Bit 3
// CS1 - PORTB Bit 4
// CS2 - PORTB Bit 5
khoidong();
xoalcd();
while (1)
{ gotoxy(0,0);
for(i=0;i<15;i++)
ghikitu(ten[i]);
ghilenh(0xc0);
for(j=0;j<8;j++)
ghikitu(lop[j]);
}
}
em sử dụng chức năng chạy từng dòng trong proteus thì thấy nó chỉ lẩn quẩn trong cái hàm con kiemtra() thôi.ai có cách khắc phục thì giúp em với 2 ngày này em điên đầu với cái này lắm ròi
Comment