|
D0~7所有引脚都需要接5529 板子吗?
程序如下 #include
#include "lcd1602.h"
int max=0,min=4095;//储存adc采样的值
unsigned long b=100;
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
LcdReset();
LcdWriteCommand(0x85);
while(1){
{
delayms(245);
LcdWriteCommand(0x01);
xszm(1,0,"Max:");
xsfd(1,4,max*3.3/4095);
max=0;
xszm(2,0,"Min:");
xsfd(2,4,min*3.3/4095);
min=4095;
xszm(2,9,"Hz");
xssz(2,11,b);
b=0;
}
}
#ifndef LCD1602_H_
#define LCD1602_H_
#include
#define uchar unsigned char
#define uint unsigned int
#define CPU_F ((double)25000000)
#define delayus(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delayms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define delays(x) __delay_cycles((long)(CPU_F*(double)x/1.0))
/**************宏定义***************/
#define DataDir P4DIR
#define DataPort P4OUT //使用P4第四位
#define CtrlDir P2DIR
/*
#define LCD_Con_DIR P6DIR
#define LCD_Con_OUT P6OUT
#define Init_LCD_Con LCD_Con_DIR|=BIT5+BIT6+BIT7
*/
#define CLR_RS P2OUT&=~BIT5; //RS = P2.5
#define SET_RS P2OUT|=BIT5;
#define CLR_EN P2OUT&=~BIT4; //EN = P2.4
#define SET_EN P2OUT|=BIT4;
#define CLR_RW P2OUT&=~BIT0; //RW = P2.0
#define SET_RW P2OUT|=BIT0;
void PlaceCom(uchar cmd)
{
DataDir &=0XF0;
DataPort&=0XF0;
DataPort|=cmd>>4;
DataDir |=0X0F;
}
void LcdWriteCommand(uchar cmd)
{
CLR_EN;
CLR_RS;
PlaceCom(cmd);
delayms(1);
SET_EN;
delayms(1);
CLR_EN;
cmd=cmd<<4; // 发送低四位
PlaceCom(cmd);
delayms(1);
SET_EN;
delayms(1);
CLR_EN;
}
void LcdWriteData( uchar data )
{
CLR_EN;
SET_RS;
PlaceCom(data);
delayms(1);
SET_EN;
delayms(1);
CLR_EN;
PlaceCom(data << 4); //写入低四位
delayms(1);
SET_EN;
delayms(1);
CLR_EN;
}
void LcdReset(void)
{
CtrlDir |= BIT4+BIT5+BIT0; //控制线端口设为输出状态
DataDir = 0xF0; //数据端口设为输出状态
LcdWriteCommand(0x33); //规定的复位操作
delayms(5);
LcdWriteCommand(0x32);
delayms(5);
LcdWriteCommand(0x28);
delayms(5);
LcdWriteCommand(0x28); //显示模式设置
LcdWriteCommand(0x08); //显示关闭
LcdWriteCommand(0x01); //显示清屏
LcdWriteCommand(0x06); //写字符时整体不移动
LcdWriteCommand(0x0c); //显示开,不开游标,不闪烁
}
void LocateXY(uchar y,uchar x) //x列 y行
{
uchar temp;
temp = x;
if(y==2) temp += 0x40; //如果在第2行
temp += 0x80;
LcdWriteCommand(temp);
}
void Disp1Char(uchar x,uchar y,char data )
{
LocateXY(x,y);
LcdWriteData(data);
}
void DispNChar(uchar x,uchar y, uchar n,uchar *ptr)
{
uchar i;
for (i=0;i
{
Disp1Char(x++,y,ptr[i]);
if (x == 0x0f)
{
x = 0;
y ^= 1;
}
}
}
void xssz(char x,char y,unsigned int long a)
{
char buf[13],i=0;
LocateXY(x,y);
sprintf(buf, "%d\n",a);
while(buf[i+1])
LcdWriteData(buf[i++]);
}
void xsfd(uchar x,uchar y,double a)
{
xssz(x,y,a);
Disp1Char(x,y+1,'.');
xssz(x,y+2,((int)(a*10))%10);
xssz(x,y+3,((int)(a*100))%10);
}
void xszm(uchar x,uchar y,char *a)
{
char i=0;
LocateXY(x,y);
while(a[i])
{
LcdWriteData(a[i++]);
}
}
#endif /* LCD1602_H_ */
|
|