新聞中心

12232F用串口的顯示程序

作者: 時(shí)間:2016-11-18 來(lái)源:網(wǎng)絡(luò) 收藏
這是12232F串口顯示程序,該程序可以通過(guò)調(diào)用函數(shù)可在任意位置顯示任意字符,供大家參考。


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

本文引用地址:http://m.butianyuan.cn/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); //數(shù)據(jù)字
Hight &= 0x0f;
Write_Byte (Hight<<=4);
CS = 0;
}
//該函數(shù)用于在指定位置顯示字符串,x為行數(shù),y為列,k為字符個(gè)數(shù)
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為行坐標(biāo),y為列坐標(biāo),k為所要顯示的漢字個(gè)數(shù)
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);//關(guān)顯示
delay ();
Write_12232 (comm,0x10);//設(shè)置光標(biāo)為右移
delay ();
Write_12232 (comm,0x06);//設(shè)置光標(biāo)整體右移時(shí)AC加1
delay ();
Write_12232 (comm,0x02);//地址歸位
delay ();
Write_12232 (comm,0x01);//清除顯示
delay ();
Write_12232 (comm,0x0c);//開(kāi)顯示,不顯示光標(biāo),光標(biāo)不反白顯示
}

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



關(guān)鍵詞: 12232F串口顯示程

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉