STC12C5A60S2两路AD采集用LCD1602显示_第1页
STC12C5A60S2两路AD采集用LCD1602显示_第2页
STC12C5A60S2两路AD采集用LCD1602显示_第3页
STC12C5A60S2两路AD采集用LCD1602显示_第4页
STC12C5A60S2两路AD采集用LCD1602显示_第5页
已阅读5页,还剩2页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、#include #include#include stdio.h#define ulong unsigned long#define uint unsigned int#define uchar unsigned charuchar data adc _at_0x30;uchar data adc1 _at_ 0x31;sbit E=P27;/1602使能引脚sbit RW=P26;/1602读写引脚sbit RS=P25;/1602数据/命令选择引脚void SendByte(unsigned char dat);void SendStr(unsigned char *s);void L1

2、602_string(uchar hang,uchar lie,uchar *p);void L1602_char(uchar hang,uchar lie,char sign);uchar AD();uchar AD1();void DelayUs2x(unsigned char t) while(-t);/*- mS延时函数,含有输入参数 unsigned char t,无返回值 unsigned char 是定义无符号字符变量,其值的范围是 0255 这里使用晶振12M,精确延时请使用汇编-*/void DelayMs(unsigned char t) while(t-) /大致延时1m

3、S DelayUs2x(245); DelayUs2x(245); void delay()_nop_();_nop_();void Delay(uint del)uint i,j;for(i=0;idel;i+)for(j=0;j=148;j+)/* 名称 : bit Busy(void)* 功能 : 这个是一个读状态函数,读出函数是否处在忙状态* 输入 : 输入的命令值* 输出 : 无*/void Busy(void)bit busy_flag = 1;P0 = 0xff;RS = 0;delay();RW = 1;delay();E = 1;/Delay(1);while(1)busy_

4、flag = (bit)(P0 & 0x80);if(busy_flag = 0)break;E = 0;/* 名称 : wcmd(uchar del)* 功能 : 1602命令函数* 输入 : 输入的命令值* 输出 : 无*/void wcmd(uchar del)RS = 0;delay();RW = 0;delay();E = 0;delay();P0 = del;delay();E = 1;delay();E = 0;/* 名称 : wdata(uchar del)* 功能 : 1602写数据函数* 输入 : 需要写入1602的数据* 输出 : 无*/void wdata(uchar

5、del)delay();RS = 1;delay();RW = 0;delay();E = 0;delay();P0 = del; delay();E = 1;delay();E = 0;/* 名称 : L1602_init()* 功能 : 1602初始化,请参考1602的资料* 输入 : 无* 输出 : 无*/void L1602_init(void)Delay(15);wcmd(0x38);Delay(5);wcmd(0x38);Delay(5);wcmd(0x38);wcmd(0x38);Busy();wcmd(0x08);Busy();wcmd(0x01);Busy();wcmd(0x

6、06);Busy();wcmd(0x0c);/* 名称 : L1602_char(uchar hang,uchar lie,char sign)* 功能 : 改变液晶中某位的值,如果要让第一行,第五个字符显示b ,调用该函数如下 L1602_char(1,5,b)* 输入 : 行,列,需要输入1602的数据* 输出 : 无*/void L1602_char(uchar hang,uchar lie,char sign)uchar a;if(hang = 1) a = 0x80;if(hang = 2)a = 0xc0;a = a + lie - 1;Busy();wcmd(a);Busy();

7、wdata(sign);/* 名称 : L1602_string(uchar hang,uchar lie,uchar *p)* 功能 : 改变液晶中某位的值,如果要让第一行,第五个字符开始显示ab cd ef ,调用该函数如下 L1602_string(1,5,ab cd ef;)* 输入 : 行,列,需要输入1602的数据* 输出 : 无*/void L1602_string(uchar hang,uchar lie,uchar *p)uchar a;if(hang = 1) a = 0x80;if(hang = 2)a = 0xc0;a = a + lie - 1;while(1)Bus

8、y();wcmd(a);Busy();wdata(*p);a+;p+;if(*p = 0)|(a=0x90)|(a=0xd0) break;uchar AD() ulong i; uchar star; ADC_CONTR|=0x80; for(i=0;i10000;i+); P1ASF=0x01; ADC_CONTR|=0XE1; for(i=0;i10000;i+); while(1) ADC_CONTR|=0x08; star=0; while(star=0) star=ADC_CONTR&0x10; ADC_CONTR&=0x00;adc=ADC_RES;/adc=2;/adc+=AD

9、C_RESL;return adc; uchar AD1() ulong i; uchar star; ADC_CONTR|=0x80; for(i=0;i10000;i+); P1ASF=0; ADC_CONTR|=0XE0; for(i=0;i10000;i+); while(1) ADC_CONTR|=0x08; star=0; while(star=0) star=ADC_CONTR&0x10; ADC_CONTR&=0x00;adc1=ADC_RES;/adc1=2;/adc1+=ADC_RESL;return adc1; void main() float i,j;unsigned char a16;unsigned char b16;L1602_init

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论