新闻中心

EEPW首页>嵌入式系统>设计应用> 12232F用串口的显示程序

12232F用串口的显示程序

作者: 时间:2016-11-18 来源:网络 收藏
这是12232F串口显示程序,该程序可以通过调用函数可在任意位置显示任意字符,供大家参考。


/* 第一行起始地址为0x80
第二行起始地址为0x90 */
#include
#include "INTRINS.H"

本文引用地址://m.amcfsurvey.com/article/201611/315571.htm

#define comm 1
#define dat 0
#define uint unsigned int
#define uchar unsigned char

sbit CS = P0^2;
sbit CLK = P0^0;
sbit STD = P0^1;


unsigned char code Chinese [] = {"欢迎使用"};

void delay ()
{
unsigned int i;
for (i=0;i<1500;i++);
}

void Write_Byte (unsigned char Data)
{
unsigned char i;
CLK = 0;
_nop_();
_nop_();
for (i=8;i>0;i--)
{
Data <<= 1;
STD = CY;
CLK = 0;
_nop_();
_nop_();
_nop_();
CLK = 1;
_nop_();
_nop_();
}
}

void Write_12232 (unsigned char Derect,unsigned char Hight)
{
CS = 0;
_nop_();
_nop_();
_nop_();
CS = 1;
if(Derect==1)
Write_Byte (0xf8); //命令字
else
Write_Byte (0xfa);
Write_Byte (Hight&0xf0); //数据字
Hight &= 0x0f;
Write_Byte (Hight<<=4);
CS = 0;
}
//该函数用于在指定位置显示字符串,x为行数,y为列,k为字符个数
void lcd_char(uchar x,uchar y,uchar k,uchar *datt)
{
uchar addr,i;
if(x==0)
addr=0x80+y;
else
addr=0x90+y;
Write_12232 (comm,addr);
for(i=0;i Write_12232 (dat,datt[i]);
}
//在指定位置显示汉字串,其中x为行坐标,y为列坐标,k为所要显示的汉字个数
void Write_Chinese (uchar x,uchar y,uchar k,uchar *p)
{
uchar addr,i;
if(x==0)
addr=0x80+y;
else
addr=0x90+y;
Write_12232 (comm,addr);
for (i=0;i<2*k;i++)
Write_12232 (dat,p [i]);

}

void init_lcd()
{
CS = 0;
Write_12232 (comm,0x08);//关显示
delay ();
Write_12232 (comm,0x10);//设置光标为右移
delay ();
Write_12232 (comm,0x06);//设置光标整体右移时AC加1
delay ();
Write_12232 (comm,0x02);//地址归位
delay ();
Write_12232 (comm,0x01);//清除显示
delay ();
Write_12232 (comm,0x0c);//开显示,不显示光标,光标不反白显示
}

void main ()
{ uchar b[4];
P0M1=0X00;
P0M0=0X00;
b[0]=5+0x30;
b[1]=6+0x30;
b[2]=0x37;
b[3]=0x38;
init_lcd();
lcd_char(0,2,4,b);
Write_Chinese (1,0,4,Chinese);
delay ();
while (1)
{
}
}



关键词:12232F串口显示程

评论


技术专区

关闭