您的位置 首页 基础

12232F用串口的显现程序

这是12232F用串口的显示程序,该程序可以通过调用函数可在任意位置显示任意字符,供大家参考。/*第一行起始地址为0x80第二行起始地址为…

这是12232F串口显现程序,该程序能够经过调用函数可在恣意方位显现恣意字符,供我们参阅。

/* 榜首行开始地址为0x80
第二行开始地址为0x90 */
#include
#include “INTRINS.H”

#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)
{
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/jichu/266097.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部