欢迎来到天天文库
浏览记录
ID:22442234
大小:98.41 KB
页数:7页
时间:2018-10-29
《压力传感器程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、//常景定义//采样值存储//超过压力表暈积最人值红色led报瞥//低于压力表fi程敁小值绿色led报//fe度变换存储单允//报警位存储单元//显示值百位//兄示值十位//显示值个位//显示值十分位//写#includeincludeincludeinclude#defineucharunsignedchar#defineuintunsignedint#defineBUSY0x80//defineDATAPORTPO//ADC0832的引脚sbitADCS=P3A5;//ADC0832chipseclects
2、bitADDI=P3A7;//ADC0832kinsbitADDO=P3八7;//ADC0832koutsbitADCLK=P3八6;//ADC0832clocksignalsbitLCM_RS=P2A0;sbitLCM_RW=P2A1;sbitLCM_EN=P2A2;ucharad_data;sbitAlarmledred=P1A5;定义sbitAlarm_led_green=Pl八6;警定义//adc采样值存储单元charpress_data;unsignedcharad_alarm;unsignedcha
3、rpress_bai=O;unsignedcharpress_shi=O;unsignedcharpress_ge=0;unsignedcharpress_dot=0;ucharcodestrO[]={"Press:.kpaucharcodestrl[]={"CheckBYJack"};voiddelay(uint);voidlcd_wait(void);voiddelay_LCM(uint);//LCD延吋子程序voidinitLCM(void);//LCD初始化子程序voidlcd_wait(void);/
4、/LCD检测忙子程序voidWriteCommandLCMfucharWCLCM,ucharBusyC);//写指令到ICM子函数voidWriteDataLCM(ucharWDLCM);数裾到LCM了函数//显示指定//显示指定华//系统voidDisplayOneChar(ucharX,ucharY'ucharDData);少标的一个字符子函数voidDisplayListChar(ucharX,ucharY'ucharcode*DData);标的一串字符子函数voiddisplay(void);显示子函数
5、ucharAdc0832(unsignedcharchannel);voidalarm(void);voiddata_pro(void);voidmain(void){delay(500);//系统延时500ms启动initLCMf);WriteCommandLCM(0x01,l);//清S不•屏DisplayUstChar(O,O,strO);DisplayUstChar(O,l,strl);while⑴{ad_data=AdcO832(O);//采样值存储单元初始化为0alarm();data_pro();
6、display!);voiddelayfuintk)uintij;for(i=0;i{for(j=0;j<60;j++){;}voidWriteCommandLCM(ucharWCLCM,ucharBusyC){if(BusyC)lcd_wait();DATAPORT=WCLCM;LCM_RS=0;//选中指令寄存器LCM_RW=0;//写模式LCM_EN=1;_nop_();_nop_();_nop_();LCM_EN=0;voidWriteDataLCM(ucharWDLCM){lcd_wait();//检
7、测tf_:信号DATAPORT=WDLCM;LCM_RS=1;//选屮数裾寄存器LCM_RW=0;//写模式LCM_EN=1;_nop_();_nop_();_nop_();LCM_EN=0;}voidlcd_wait(void){DATAPORT=Oxff;//读LCD前若单片机输出低也平,而读岀LCD为高电平,则冲突,Proteus仿真会有示逻辑黄色LCM_EN=1;LCM_RS=0;LCM_RW=1;_nop_();_nop_();_nop_();while(DATAPORT&BUSY){LCM_EN=O
8、;_nopj);_nop_();LCM_EN=1;_nopj);_nopj);}LCM_EN=O;}voidinitLCM(){DATAPORT=0;delay(15);WriteCommandLCM(0x38,0);//三次.W不•榄式设置,不检测tL•信号delay⑸;WriteCommandLCM(0x38,0);delay(5);WriteCommandLCM(0x38,0);
此文档下载收益归作者所有