智能车制作
标题:
xs128显示LCD1602的问题
[打印本页]
作者:
ngngabc
时间:
2011-3-12 20:12
标题:
xs128显示LCD1602的问题
#include <hidef.h> /* common defines and macros */
试过很多程序,包括别人实验过的程序,LCD都显示不了东西,这是为什么
#include "derivative.h" /* derivative-specific definitions */
#define LCD1602_RS PORTB_PB0
#define LCD1602_RW PORTB_PB1
#define LCD1602_EN PORTB_PB2
#define LCDIO PORTA
#define LCDIO_DIR DDRA
#define LCDIO_DIR_IN 0x00
#define LCDIO_DIR_OUT 0xFF
void SetBusCLK_16M(void)
{
CLKSEL=0X00; // disengage PLL to system
PLLCTL_PLLON=1; // turn on PLL
SYNR=0x00 | 0x01; // VCOFRQ[7:6];SYNDIV[5:0]
// fVCO= 2*fOSC*(SYNDIV + 1)/(REFDIV + 1)
// fPLL= fVCO/(2 × POSTDIV)
// fBUS= fPLL/2
// VCOCLK Frequency Ranges VCOFRQ[7:6]
// 32MHz <= fVCO <= 48MHz 00
// 48MHz < fVCO <= 80MHz 01
// Reserved 10
// 80MHz < fVCO <= 120MHz 11
REFDV=0x80 | 0x01; // REFFRQ[7:6];REFDIV[5:0]
// fREF=fOSC/(REFDIV + 1)
// REFCLK Frequency Ranges REFFRQ[7:6]
// 1MHz <= fREF <= 2MHz 00
// 2MHz < fREF <= 6MHz 01
// 6MHz < fREF <= 12MHz 10
// fREF > 12MHz 11
// pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
POSTDIV=0x00; // 4:0, fPLL= fVCO/(2xPOSTDIV)
// If POSTDIV = $00 then fPLL is identical to fVCO (divide by one).
_asm(nop); // BUS CLOCK=16M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void write_cmd(unsigned char cmd,unsigned BusyC) {
if (BusyC) ReadStatus(); //Test it busy or not
LCDIO=cmd;
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_EN=0;
LCD1602_EN=0;
LCD1602_EN=1;
}
void write_data(uchar dat,unsigned BusyC) {
if (BusyC) ReadStatus(); //Test it busy or not
LCDIO=dat;
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_EN=0;
LCD1602_EN=0;
LCD1602_EN=1;
}
int ReadStatus(void)
{
uchar cRtn;
LCDIO_DIR = LCDIO_DIR_IN;
LCD1602_RS = 0;
LCD1602_RW = 1;
LCD1602_EN = 0;
LCD1602_EN = 0;
LCD1602_EN = 1;
while (LCDIO&0x80); //Test Busy State
cRtn = LCDIO_DIR; // if Not save the port value, it should be change
LCDIO_DIR = LCDIO_DIR_OUT;
return(cRtn);
}
void LcdDelay(){
int i, j;
for (i = 0; i < 300; i++)
for(j = 0; j < 3000; j++);
}
void lcd_init() {
DDRA = 0xff;
DDRB = 0xff;
LCDIO_DIR = LCDIO_DIR_OUT;
LcdDelay();
write_cmd(0x01,0); //clear screen
write_cmd(0x38,1); //set 8 bit data transmission mode
write_cmd(0x06,1); // cursor right, disable moving
write_cmd(0x0f,1); //open display (enable lcd display)
write_cmd(0x80,1); //set lcd first display address
write_cmd(0x01,1); //clear screen
}
void main(void) {
/* put your own code here */
SetBusCLK_16M();
lcd_init();
EnableInterrupts;
for(;;) {
write_data('f',1);
DDRE_DDRE5=1;
PORTE_PE5=0;
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
复制代码
作者:
turf456
时间:
2011-3-12 21:07
写操作要加延时。不同的1602延时还不一样。多试试。控制方式一般都一样。
作者:
ngngabc
时间:
2011-3-16 18:31
回复
2#
turf456
不是用了忙检测就不用延时吗,要是延时的话怎样根据1602来确定延时呢?
作者:
tongyonghua123
时间:
2011-10-6 19:16
求二楼解释
作者:
记忆将军
时间:
2011-10-6 19:28
不同的总线时钟 延时不一样
作者:
XHM
时间:
2011-10-24 21:16
使能不是应该是上升沿的啊?我也是新手,望请教。
作者:
清明
时间:
2011-11-12 20:57
xs
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2