初学者arduino编程在LCD上显示文字 应该怎么写程序 ?

初学者arduino编程在LCD上显示文字 应该怎么写程序 ?,第1张

//端口定义 诺基亚5110显示屏

int LCD_CE=2

int LCD_RST=3

int SCLK=4

int SDIN=5

int LCD_DC=6

int inputPin=8 // 定义超声波信号接收接口

int outputPin=9// 定义超声波信号发出接口

/****************************************************************/

void setup()

{

pinMode(inputPin, INPUT)

pinMode(outputPin, OUTPUT)

}

//****************************定义ASCII字符**********************//

/**********************************

6 x 8 font

1 pixel space at left and bottom

index = ASCII - 32

***********************************/

const unsigned char font6x8[][6] =

{

{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp

{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !

{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "

{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #

{ 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $

{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %

{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &

{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '

{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (

{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )

{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *

{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +

{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,

{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -

{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .

{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /

{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0

{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1

{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2

{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3

{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4

{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5

{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6

{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7

{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8

{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9

{ 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :

{ 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, //

{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <

{ 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =

{ 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >

{ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?

{ 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @

{ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A

{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B

{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C

{ 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D

{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E

{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F

{ 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G

{ 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H

{ 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I

{ 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J

{ 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K

{ 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L

{ 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M

{ 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N

{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O

{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P

{ 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q

{ 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R

{ 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S

{ 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T

{ 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U

{ 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V

{ 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W

{ 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X

{ 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y

{ 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z

{ 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [

{ 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55

{ 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]

{ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^

{ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _

{ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '

{ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a

{ 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b

{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c

{ 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d

{ 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e

{ 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f

{ 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g

{ 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h

{ 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i

{ 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j

{ 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k

{ 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l

{ 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m

{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n

{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o

{ 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p

{ 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q

{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r

{ 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s

{ 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t

{ 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u

{ 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v

{ 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w

{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x

{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y

{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z

{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 }// horiz lines

}

/************************LCD初始化函数********************************/

void LCD_init(void)

{

//先设置为输出

pinMode(SCLK,OUTPUT)

pinMode(SDIN,OUTPUT)

pinMode(LCD_DC,OUTPUT)

pinMode(LCD_CE,OUTPUT)

pinMode(LCD_RST,OUTPUT)

// 产生一个让LCD复位的低电平脉冲

digitalWrite( LCD_RST, LOW)

delayMicroseconds(1)

digitalWrite( LCD_RST, HIGH)

// 关闭LCD

digitalWrite( LCD_CE, LOW)

delayMicroseconds(1)

// 使能LCD

digitalWrite( LCD_CE, HIGH)//LCD_CE = 1

delayMicroseconds(1)

LCD_write_byte(0x21, 0)// 使用扩展命令设置LCD模式

LCD_write_byte(0xc8, 0)// 设置偏置电压

LCD_write_byte(0x06, 0)// 温度校正

LCD_write_byte(0x13, 0)// 1:48

LCD_write_byte(0x20, 0)// 使用基本命令

LCD_clear()// 清屏

LCD_write_byte(0x0c, 0)// 设定显示模式,正常显示

// 关闭LCD

digitalWrite( LCD_CE, LOW) //LCD_CE = 0

}

/************************LCD清屏函数*******************************/

void LCD_clear(void)

{

unsigned int i

LCD_write_byte(0x0c, 0)

LCD_write_byte(0x80, 0)

for (i=0i<504i++)

{

LCD_write_byte(0, 1)

}

}

/*************************设置字符位置函数**************************/

void LCD_set_XY(unsigned char X, unsigned char Y)

{

LCD_write_byte(0x40 | Y, 0)// column

LCD_write_byte(0x80 | X, 0)// row

}

/*************************ASCII字符显示函数*************************/

void LCD_write_char(unsigned char c)

{

unsigned char line

c -= 32

for (line=0line<6line++)

{

LCD_write_byte(font6x8[c][line], 1)

}

}

/*******************************************************************/

/*-------------------------------------------------

LCD_write_english_String : 英文字符串显示函数

输入参数:*s :英文字符串指针;

X、Y: 显示字符串的位置,x 0-83 ,y 0-5

--------------------------------------------------*/

void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)

{

LCD_set_XY(X,Y)

while (*s)

{

LCD_write_char(*s)

s++

}

}

/******************************************************************/

/*---------------------------------------------

LCD_write_byte: 写数据到LCD

输入参数:data:写入的数据;

command :写数据/命令选择;

---------------------------------------------*/

void LCD_write_byte(unsigned char dat, unsigned char command)

{

unsigned char i

digitalWrite( LCD_CE, LOW)// 使能LCD_CE = 0

if (command == 0)

{

digitalWrite( LCD_DC, LOW)// 传送命令 LCD_DC = 0

}

else

{

digitalWrite( LCD_DC, HIGH)// 传送数据LCD_DC = 1

}

for(i=0i<8i++)

{

if(dat&0x80)

{

digitalWrite( SDIN, HIGH)//SDIN = 1

}

else

{

digitalWrite( SDIN, LOW)//SDIN = 0

}

digitalWrite( SCLK, LOW)//SCLK = 0

dat = dat <<1

digitalWrite( SCLK, HIGH)//SCLK = 1

}

digitalWrite( LCD_CE, HIGH)//LCD_CE = 1

}

/*************************以下为主函数*****************************/

void loop()

{

LCD_init()//初始化液晶

LCD_clear()

LCD_write_english_string(0,0," --Arduino-- ")

LCD_write_english_string(0,2,"Renge:")

LCD_write_english_string(0,4,"DESIGN BY KENT")

LCD_write_english_string(0,5,"2010.6")

while(1)

{

digitalWrite(outputPin, LOW)// 使发出发出超声波信号接口低电平2μs

delayMicroseconds(2)

digitalWrite(outputPin, HIGH)// 使发出发出超声波信号接口高电平10μs,这里是至少10μs

delayMicroseconds(10)

digitalWrite(outputPin, LOW) // 保持发出超声波信号接口低电平

int distance = pulseIn(inputPin, HIGH) // 读出脉冲时间

distance= distance/58 // 将脉冲时间转化为距离(单位:厘米)

if(distance>120)

{

LCD_write_english_string(35,2,"???")

}

else

{

LCD_write_english_string(60,2,"cm")

LCD_set_XY(35, 2)

LCD_write_char( 0x30+distance%1000/100)//显示百位数

LCD_write_char( 0x30+distance%100/10) //显示十位数

LCD_write_char( 0x30+distance%10) //显示个位数

}

delay(10)

}

}

#include <reg52.h>

#define uchar unsigned char

#define uint unsigned int

uchar rebuf[11]

uchar tembuf[2]={28,20}

sbitsce = P0^0 //片选

sbitres = P0^1 //复位,0复位

sbitdc = P0^2 //1写数据,0写指令

sbitsdin = P0^3 //数据

sbitsclk = P0^4 //时钟

sbiten = P3^2

sbitkey1 = P1^0

sbitkey2 = P1^1

sbitkey3 = P1^2

sbitkey4 = P1^3

sbitkey5 = P1^4

sbitkey6 = P1^5

sbitalarm = P2^7

uchar dp=0,re_data,keynum = 0

bit full=0,f_alarm=0,m_alarm = 0

unsigned char code shuzi[]={

/*-- 文字: 0 --*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,

/*-- 文字: 1 --*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,

/*-- 文字: 2 --*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,

/*-- 文字: 3 --*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,

/*-- 文字: 4 --*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,

/*-- 文字: 5 --*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,

/*-- 文字: 6 --*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,

/*-- 文字: 7 --*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,

/*-- 文字: 8 --*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,

/*-- 文字: 9 --*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,

/*-- 文字: . --10*/

/*-- 宋体12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,

/*-- 文字: : --11*/

/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=8x16 --*/

0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,

/*-- 调入了一幅图像:这是您新建的图像 --12*/

/*-- 宽度x高度=8x16 --*/

0x0C,0x12,0x0C,0x80,0x40,0x20,0x20,0x20,0x00,0x00,0x00,0x0F,0x10,0x20,0x20,0x20,

}

unsigned char code hanzi[]=

{

/*-- 文字: 光 0--*/

/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/

0x00,0x40,0x42,0x44,0x5C,0xC8,0x40,0x7F,0x40,0xC0,0x50,0x4E,0x44,0x60,0x40,0x00,

0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,

/*-- 空白 1--*/

/*-- 宽度x高度=16x16 --*/

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*-- 一级光 2--*/

/*-- 宽度x高度=16x16 --*/

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*-- 二级光 3--*/

/*-- 宽度x高度=16x16 --*/

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*-- 三级光 4--*/

/*-- 宽度x高度=16x16 --*/

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,

0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,

/*-- 四级光 5--*/

/*-- 宽度x高度=16x16 --*/

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,

0xF0,0xF0,0xF0,0x00,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0x00,

/*-- 文字: 报 6--*/

/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/

0x08,0x08,0x88,0xFF,0x48,0x28,0x00,0xFF,0xC1,0x41,0x41,0x49,0x51,0xCF,0x00,0x00,

0x01,0x41,0x80,0x7F,0x00,0x00,0x00,0xFF,0x40,0x23,0x14,0x1C,0x33,0x60,0x20,0x00,

/*-- 文字: 警 7--*/

/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/

0x20,0x1A,0xFA,0xAF,0xAA,0xEF,0x0A,0xFA,0x10,0x8F,0x54,0x24,0x5C,0x84,0x04,0x00,

0x02,0x02,0x02,0xEA,0xAA,0xAA,0xAB,0xAA,0xAB,0xAA,0xAA,0xEA,0x02,0x02,0x03,0x00,

/*-- 文字: 温 8--*/

/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/

0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,

0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00,

/*-- 文字: 度 9--*/

/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/

0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,

0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,

/*-- 文字: 高 10--*/

/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/

0x04,0x04,0x04,0x04,0x74,0x54,0x55,0x56,0x54,0x54,0x74,0x04,0x04,0x04,0x04,0x00,

0x00,0xFF,0x01,0x01,0x3D,0x25,0x25,0x25,0x25,0x25,0x3D,0x41,0x81,0x7F,0x00,0x00,

/*-- 文字: 低 11--*/

/*-- Trebuchet MS12 此字体下对应的点阵为:宽x高=16x16 --*/

0x40,0x20,0xF0,0x0C,0x07,0x02,0xFC,0x44,0x44,0x42,0xFE,0x43,0x43,0x42,0x40,0x00,

0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x20,0x10,0x28,0x43,0x0C,0x10,0x20,0x78,0x00,

}

/************************************************************

延迟函数

函数原型:void delay(uint z)

函数功能:延迟z毫秒

*************************************************************/

void delay(uint z)

{

uint x,y

for(x=zx>0x--)

for(y=110y>0y--)

}

/*--------------------------------------------

LCD_write_byte: 使用SPI接口写数据到LCD

输入参数:dt:写入的数据;

command :写数据/命令选择;

编写日期:20080918

----------------------------------------------*/

void LCD_write_byte(unsigned char dt, unsigned char command)

{

unsigned char i

sce=0

dc=command

for(i=0i<8i++)

{

if(dt&0x80)

sdin=1

else

sdin=0

dt=dt<<1

sclk=0

sclk=1

}

dc=1

sce=1

sdin=1

}

/*---------------------------------------

LCD_init: 3310LCD初始化

编写日期:20080918

----------------------------------------- */

void LCD_init(void)

{

res=0

delay(1)

res=1

LCD_write_byte(0x21,0)//初始化Lcd,功能设定使用扩充指令

LCD_write_byte(0xd0,0)//设定液晶偏置电压

LCD_write_byte(0x20,0)//使用基本指令

LCD_write_byte(0x0C,0)//设定显示模式,正常显示

}

/*-------------------------------------------

LCD_set_XY: 设置LCD坐标函数

输入参数:X:0-83 Y:0-5

编写日期:20080918

---------------------------------------------*/

void LCD_set_XY(unsigned char X, unsigned char Y)

{

LCD_write_byte(0x40 | Y, 0)// column

LCD_write_byte(0x80 | X, 0)// row

}

/*------------------------------------------

LCD_clear: LCD清屏函数

编写日期:20080918

--------------------------------------------*/

void LCD_clear(void)

{

unsigned char t

unsigned char k

LCD_set_XY(0,0)

for(t=0t<6t++)

{

for(k=0k<84k++)

{

LCD_write_byte(0x00,1)

}

}

}

/*---------------------------------------------

LCD_write_shu: 显示8(宽)*16(高)点阵列数字字母符号等半角类

输入参数:c:显示的字符;

编写日期:20080918

-----------------------------------------------*/

void LCD_write_shu(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符

{

unsigned char i

LCD_set_XY(row*8, page)// 列,页

for(i=0i<8i++)

{

LCD_write_byte(shuzi[c*16+i],1)

}

LCD_set_XY(row*8, page+1)// 列,页

for(i=8i<16i++)

{

LCD_write_byte(shuzi[c*16+i],1)

}

}

/*---------------------------------------------

LCD_write_hanzi: 显示16(宽)*16(高)点阵列汉字等半角类

输入参数:c:显示的字符;

编写日期:20080918

-----------------------------------------------*/

void LCD_write_hanzi(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符

{

unsigned char i

LCD_set_XY(row*8, page)// 列,页

for(i=0i<16i++)

{

LCD_write_byte(hanzi[c*32+i],1)

}

LCD_set_XY(row*8, page+1)// 列,页

for(i=16i<32i++)

{

LCD_write_byte(hanzi[c*32+i],1)

}

}

/*---------------------------------------------

void display(): 显示函数

输入参数:无;

编写日期:2009,10

-----------------------------------------------*/

void display()

{

if(rebuf[10]==0xaa)

{

LCD_write_shu(1,0,rebuf[1]) //ID1

LCD_write_shu(2,0,rebuf[2]) //ID2

LCD_write_shu(3,0,rebuf[3]) //ID3

LCD_write_shu(0,2,rebuf[4]) //tem1

LCD_write_shu(1,2,rebuf[5]) //tem2

LCD_write_shu(2,2,10) //.

LCD_write_shu(3,2,rebuf[6]) //tem3

LCD_write_shu(4,2,12) //℃

LCD_write_hanzi(0,4,0) //光

LCD_write_shu(2,4,11) //:

LCD_write_hanzi(3,4,(rebuf[8]+1)) //

if((rebuf[4]>=(tembuf[0]/10))&&(rebuf[5]>=(tembuf[0]%10)))

f_alarm = 1

else

f_alarm = 0

if((rebuf[4]<=(tembuf[1]/10))&&(rebuf[5]<=(tembuf[1]%10)))

f_alarm = 1

else

f_alarm = 0

}

if(rebuf[10]==0xbb)

{

LCD_write_shu(6,0,rebuf[1]) //ID1

LCD_write_shu(7,0,rebuf[2]) //ID2

LCD_write_shu(8,0,rebuf[3]) //ID3

LCD_write_shu(5,2,rebuf[4]) //tem1

LCD_write_shu(6,2,rebuf[5]) //tem2

LCD_write_shu(7,2,10) //.

LCD_write_shu(8,2,rebuf[6]) //tem3

LCD_write_shu(9,2,12) //℃

LCD_write_hanzi(5,4,0) //光

LCD_write_shu(7,4,11) //:

LCD_write_hanzi(8,4,(rebuf[8]+1)) //

if((rebuf[4]>=(tembuf[0]/10))&&(rebuf[5]>=(tembuf[0]%10)))

m_alarm = 1

else

m_alarm = 0

if((rebuf[4]<=(tembuf[1]/10))&&(rebuf[5]<=(tembuf[1]%10)))

m_alarm = 1

else

m_alarm = 0

}

}

偏置(Bias)

LCD 的 SEG/COM 的驱动波形为模拟信号, 而各档模拟电压相对于 LCD 输出的最

高电压的比例称为偏置,而一般来讲,Bias 是以最低一档与输出最高电压的

比值来表示

一般而言,Bias 和 Duty 之间是有一定关系的,duty 数越多,每根 COM 对应

的扫描时间变短,而要达到同样的显示亮度和显示对比度,VON 的电压就要提

高,选电平和非选电平的差异需要加大,即 Bias 需要加大,Duty 和 Bias 间

有一经验公式,即

BISA=1/(duty的平方根+1)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11264713.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存