GP2Y0A21例程

上传人:cl****1 文档编号:551633763 上传时间:2023-07-05 格式:DOC 页数:12 大小:26.50KB
返回 下载 相关 举报
GP2Y0A21例程_第1页
第1页 / 共12页
GP2Y0A21例程_第2页
第2页 / 共12页
GP2Y0A21例程_第3页
第3页 / 共12页
GP2Y0A21例程_第4页
第4页 / 共12页
GP2Y0A21例程_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《GP2Y0A21例程》由会员分享,可在线阅读,更多相关《GP2Y0A21例程(12页珍藏版)》请在金锄头文库上搜索。

1、/* 用法: LCD_init(); LCD_write_string(列,行,字符串); LCD_write_char(列,行,字符); -下面是STC与LCD连接信息LCD data P0.4-P0.7 RS P2.4 EN P2.6 RW P2.5(RW可不用端口,直接接地)要使用本驱动,变化下面配备信息即可-*/#include #include #define ADC_POWER 0x80#define ADC_FLAG 0x10#define ADC_START 0x08#define ADC_SPEEDLL 0x00#define ADC_SPEEDL 0x20#define A

2、DC_SPEEDH 0x40#define ADC_SPEEDHH 0x60#define uchar unsigned char#define uint unsigned int #define LCD_DATA_PORT P0 #define LCD_RS P24 / out#define LCD_EN P26 / out#define LCD_RW P25 / out 可以直接接地uchar dis1=CCFROBOT IR:0A21;uchar dis2=Range: cm;uchar ch=0;uint ADC_HS;uchar bai,shi,ge;uchar buf6;uint

3、A2D;/*-函数阐明-*/void LCD_init(void);void LCD_en_write(void);void LCD_write_command(uchar command) ;void LCD_write_data(uchar data1);/(uchar data);不能定义为data,data在kiel51中是核心词。void LCD_set_xy (uchar x, uchar y);void LCD_write_string(uchar X,uchar Y,uchar *s);void LCD_write_char(uchar X,uchar Y,uchar data

4、1);/-void delay_1us(void) /1us延时函数 _nop_();/asm(nop); void delay_nus(uint n) /N us延时函数 uint i=0; for (i=0;i0;b-) for(a=12;a0;a-); void delay_nms(uint n) /N ms延时函数 uint i=0; for (i=0;in;i+) delay_1ms(); void LCD_init(void) /液晶初始化 LCD_RW=0; /RW=0 LCD_write_command(0x38); LCD_en_write(); delay_nus(40);

5、 LCD_write_command(0x38); /0x38为8位显示 0x28为4位显示 LCD_write_command(0x0c); /显示开 LCD_write_command(0x01); /清屏 delay_nms(2); void LCD_en_write(void) /液晶使能 LCD_EN=1; delay_nus(1); LCD_EN=0;void LCD_write_command(uchar command) /写指令/*/连线为高4位旳写法 delay_nus(16); LCD_RS=0; /RS=0 LCD_DATA_PORT&=0X0f; /清高四位 LCD_

6、DATA_PORT|=command&0xf0; /写高四位 LCD_en_write(); command=command4)&0x0f; /写高四位 LCD_en_write(); LCD_DATA_PORT&=0xf0; /清高四位 LCD_DATA_PORT|=command&0x0f; /写低四位 LCD_en_write(); */ void LCD_write_data(uchar data1) /写数据 /* /连线为高4位旳写法 delay_nus(16); LCD_RS=1; /RS=1 LCD_DATA_PORT&=0X0f; /清高四位 LCD_DATA_PORT|=d

7、ata1&0xf0; /写高四位 LCD_en_write(); data1=data14)&0x0f; /写高四位 LCD_en_write(); LCD_DATA_PORT&=0Xf0; /清高四位 LCD_DATA_PORT|=data&0x0f; /写低四位 LCD_en_write();*/ void LCD_set_xy( uchar x, uchar y ) /写地址函数 uchar address; if (y = 0) address = 0x80 + x; else address = 0xc0 + x; LCD_write_command( address); void

8、LCD_write_string(uchar X,uchar Y,uchar *s) /列x=015,行y=0,1 LCD_set_xy( X, Y ); /写地址 while (*s!=0) / 写显示字符 LCD_write_data( *s ); s +; void LCD_write_char(uchar X,uchar Y,uchar data1) /列x=015,行y=0,1 LCD_set_xy( X, Y ); /写地址 LCD_write_data( data1); void AD_Init()P1ASF = 0x01;ADC_RES = 0;ADC_CONTR = ADC_

9、POWER|ADC_SPEEDLL|ADC_START|ch;delay_nms(2);void GetADCResult()ADC_CONTR = ADC_POWER|ADC_SPEEDLL|0|ADC_START;_nop_();_nop_();_nop_();_nop_();while(!(ADC_CONTR&ADC_FLAG);ADC_CONTR&=ADC_FLAG;A2D=ADC_RES*256+ADC_RESL;ADC_HS = (7605/(A2D+12)-4;/return ADC_HS;void Count()bai=(ADC_HS/100+48);shi=(ADC_HS%100/10+48);ge=(ADC_HS%100%10+48);buf0 = bai;buf1 = shi;buf2 = ge;buf3 = 0x0d;buf4 = 0x0a;buf5 = 0x00;void main()AUXR1=0x04;LCD_init(); AD_Init();LCD_write_string(0,0,dis1);LCD_write_string(0,1,di

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号