STC12C5A60S2 AD转换C语言程序,转换结果在1602液晶上显示。

STC12C5A60S2 AD转换C语言程序,转换结果在1602液晶上显示。,第1张

//1602 四线制驱动程序,根据需要自己改端口定陵猛义和延时

#define LINE1 0

#define LINE2 1

#define LINE1_HEAD 0x80

#define LINE2_HEAD 0xC0

#define CLEARSCREEN LCD_en_com(0x01)LCD_delay(30)

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

//change this part at different board

sbit DB7=P2^7

sbit DB6=P2^6

sbit DB5=P2^5

sbit DB4=P2^4

sbit LCD1602_RS=P2^1 //data command select 1 data 0 command pin 4

sbit LCD1602_RW=P2^2 //read write select 1 read 0 write pin 5

sbit LCD1602_EN=P2^3 /尺渣桥/LCD enable signal pin 6

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

void LCD_delay(unsigned int n)

{

unsigned int i=0,j=0

for (i=ni>0i--)

for (j=0j<12j++)

}

void LCD_en_com(unsigned char command)

{

DB7=(command>>7)%2

DB6=(command>>6)%2

DB5=(command>>5)%2

DB4=(command>>4)%2

LCD1602_RS = 0 //RS 0

LCD1602_RW = 0 //RW 0

LCD1602_EN = 1 //EN --\|/__ Write command

LCD_delay(2)

LCD1602_EN = 0

DB7=(command>>3)%2

DB6=(command>>2)%2

DB5=(command>>1)%2

DB4=(command>>0)%2

LCD1602_RS = 0 //RS 0

LCD1602_RW = 0 //RW 0

LCD1602_EN = 1 //EN --\|/__ Write command

LCD_delay(2)

LCD1602_EN = 0

}

void LCD_en_dat(unsigned char command)

{

DB7=(command>>7)%2

DB6=(command>>6)%2

DB5=(command>>5)%2

DB4=(command>>4)%2

LCD1602_RS = 1 /梁神/RS 1

LCD1602_RW = 0 //RW 0

LCD1602_EN = 1 //EN --\|/__ Write data

LCD_delay(2)

LCD1602_EN = 0

DB7=(command>>3)%2

DB6=(command>>2)%2

DB5=(command>>1)%2

DB4=(command>>0)%2

LCD1602_RS = 1 //RS 1

LCD1602_RW = 0 //RW 0

LCD1602_EN = 1 //EN --\|/__ Write data

LCD_delay(2)

LCD1602_EN = 0

}

void LCD_set_xy(unsigned char x,unsigned char y)

{

unsigned char address

if(y == LINE1)

address = LINE1_HEAD + x

else

address = LINE2_HEAD + x

LCD_delay(10)

LCD_en_com(address)

}

void LCD_write_string(unsigned char x,unsigned char y,unsigned char *s)

{

LCD_set_xy(x,y)

while(*s)

{

LCD_en_dat(*s)

s++

}

}

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

void InitTimer0(void)//200us

{

TMOD = 0x01

TH0 = 0x0FE

TL0 = 0x70

EA = 1

ET0 = 1

TR0 = 1

}

unsigned char LCD_ContCount=0

sbit LCDCONT=P2^0

void Timer0Interrupt(void) interrupt 1

{

TH0 = 0x0FE

TL0 = 0x70

if(LCD_ContCount<LCD_CONTRAST){LCDCONT=0}

else{LCDCONT=1}

LCD_ContCount++

if(LCD_ContCount==100){LCD_ContCount=0}

}

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

void LCD_init(void)

{

LCD_delay(50)

LCD_en_com(0x33)//原来1602初始化成4位数据线之前必需先初始化成8位(此时命令发送方式是8位格式,但数据线只需接4位)

LCD_delay(10)

LCD_en_com(0x32)//然后再改到4位线宽,这样初始化才稳定

LCD_delay(10)

LCD_en_com(0x28)//四线模式设置

LCD_delay(10)

LCD_en_com(0x0c)//显示开--对应开关显示控制指令

LCD_delay(10)

CLEARSCREEN

InitTimer0()

}

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

至于AD,用片上自带的AD就行,没有具体的电路,只能帮你这些了。

另:楼上说用ADC0834的,STC12C5A60S2已经有AD了啊

要个单片凯皮机MCU,就是AD连接到MCU的IO口,采集读取IO口渗李数据,8位AD一共可产生255个值,丛孙迟读取的值在赋给1602

液晶显示器

的IO口。


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存