专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
51单片机
求大神帮忙看下延时怎么改
2019-07-15 08:23
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
10091
1
1664
帮忙
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
1条回答
泰小呆
2019-07-15 16:54
//程序头函数
#include <reg52.h>
//显示函数
//宏定义
#define uint unsigned int
#define uchar unsigned char
#define Data_ADC0809 P1
//管脚声明
sbit LED_yanwu= P2^1;
sbit baojing= P2^5;
//ADC0809
sbit ST=P3^3;
sbit EOC=P3^6;
sbit OE=P3^2;
//按键
sbit Key1=P2^6;
sbit Key2=P2^7;
sbit Key3=P3^7;
signed char y; //浓度值全局变量
uint c; //浓度值全局变量
bit bdata flag=0;
//co含量变量
uchar nongdu;
uchar yushe_yanwu=45;
//按钮模式|
uchar Mode=0;
//函数声明
extern uchar ADC0809();
extern void Key();
void delay(uint z)
{
uint i,j;
for(i=0;i<z;i++)
for(j=0;j<121;j++);
}
//ADC0809读取信息
uchar ADC0809()
{
uchar yanwu_=0x00;
//转化初始化
ST=0;
//开始转换
ST=1;
ST=0;
//外部中断等待AD转换结束
while(EOC==0)
//读取转换的AD值
OE=1;
yanwu_=Data_ADC0809;
OE=0;
return yanwu_;
}
void Key()
{ //模式选择
void write_com()
if(Key1==0)
{
while(Key1==0);
if(Mode>=3) Mode=0;
else
{
}
}
if(Key2==0&&Mode!=0)
{
while(Key2==0);
switch(Mode)
{
case 1:
{
yushe_yanwu++;
if(yushe_yanwu>=255)
yushe_yanwu=255;
write_com(0x80+13);
write_data(0x30+yushe_yanwu/100);
write_data(0x30+yushe_yanwu%100/10);
write_data(0x30+yushe_yanwu%10);
break;
}
}
}
if(Key3==0&&Mode!=0)
{
while(Key3==0);
switch(Mode)
{
case 1:
{
yushe_yanwu--;
if(yushe_yanwu<=0)
yushe_yanwu=0;
write_data(0x30+yushe_yanwu%100/10);
write_data(0x30+yushe_yanwu%10);
break;
}
}
}
delay(200);
}
/*****************************************************************
iic控制1602 lcd
*****************************************************************/
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit SCL = P1^5;
sbit SDA = P1^6;
char ADDR = 0x7E;
void delay(int ms);
void IIC_start(void);
void IIC_stop(void);
void IIC_writeByte(char temp);
void send_command(char comm);
void send_data(char data1);
void init_lcd(void);
void clear_lcd(void);
void print_lcd(int x, int y, char *str);
void print_customer(int x, int y, char str[]);
void main(){
unsigned char table[]={0x10,0x06,0x09,0x08,0x08,0x09,0x06,0x00}; //×?·???
unsigned char table1[]={
0x03,0x07,0x0f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x18,0x1E,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x07,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x10,0x18,0x1c,0x1E,0x1E,0x1E,0x1E,0x1E,
0x0f,0x07,0x03,0x01,0x00,0x00,0x00,0x00,
0x1f,0x1f,0x1f,0x1f,0x1f,0x0f,0x07,0x01,
0x1f,0x1f,0x1f,0x1f,0x1f,0x1c,0x18,0x00,
0x1c,0x18,0x10,0x00,0x00,0x00,0x00,0x00
};//????°?
init_lcd();
print_lcd(0,0,"Hello! >_<");
print_lcd(0,1," I Love U -Gao W");
//print_customer(0,0,table);
while(1);
}
void delay(int ms){
unsigned char y ;
while(ms--){
for(y = 0 ; y<250 ; y++){
_nop_() ;
_nop_() ;
_nop_() ;
_nop_() ;
}
}
}
void IIC_start(void){
SDA=1;
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=0;
}
//????????
void IIC_stop(void){
SDA=0;
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1;
_nop_();
_nop_();
_nop_();
_nop_();
}
void IIC_writeByte(char temp){
char i;
for(i=0;i<8;i++){
SDA=(bit)(temp & 0x80) ;
temp <<=1;
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=0;
}
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1;
_nop_();
_nop_();
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
while(SDA);
_nop_();
SCL=0;
}
void send_command(char comm){
char tmp;
IIC_start();
IIC_writeByte(ADDR);
tmp = comm & 0xF0;
tmp |= 0x0C; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay(20);
tmp &= 0xFB; //Make EN = 0
IIC_writeByte(tmp);
tmp = (comm & 0x0F) << 4 ;
tmp |= 0x0C; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay(20);
tmp &= 0xFB; // Make EN = 0
IIC_writeByte(tmp);
//stop_8574();
}
void send_data(char data1){
char tmp;
IIC_start();
IIC_writeByte(ADDR);
tmp = data1 & 0xF0;
tmp |= 0x0D; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay(20);
tmp &= 0xFB; //Make EN = 0
IIC_writeByte(tmp);
tmp = (data1 & 0x0F) << 4 ;
tmp |= 0x0D; //RS = 0, RW = 0, EN = 1
IIC_writeByte(tmp);
delay(20);
tmp &= 0xFB ; // Make EN = 0
IIC_writeByte(tmp);
}
//LCD????"?
void init_lcd(void){
send_command(0x33);
delay(50) ;
send_command(0x32);
delay(50) ;
send_command(0x28);
delay(50) ;
send_command(0x0C);
delay(50) ;
send_command(0x06);
delay(50) ;
send_command(0x01);
delay(50) ;
}
//Clear Screen
void clear_lcd(void){
send_command(0x01);
}
void print_lcd(int x, int y, char *str){
char addr;
if( x < 0){
x = 0;
}
if(x > 15){
x = 15;
}
if(y<0){
y = 0;
}
if(y > 1){
y = 1;
}
// Move cursor
addr = 0x80 + 0x40 * y + x;
send_command(addr);
while (*str) {
send_data(*str++);
}
}
void print_customer(int x, int y, char *str){
unsigned char i,tmp;
for(i=0;i<8;i++){
send_command(0x40+i);
send_data(*str++);
}
}
/****************************************************
结束
****************************************************/
void main()
{
check_nongdu();
check_nongdu();
Init_lcd();
while(1)
{
yanwu=ADC0809();
check_nongdu();
Key();
if(Mode==0)
{
Display_lcd(yushe_yanwu,c,nongdu);
if(nongdu>=yushe_yanwu)
{
LED_yanwu=0;
baojing=0;
}
else
{
LED_yanwu=1;
}
if((nongdu<yushe_yanwu))
{
baojing=1;
}
}
}
}
复制代码
加载中...
一周热门
更多
>
相关问题
【东软载波ESF0654 PDS开发板活动】开箱
1 个回答
东软载波ESF0654 PDS开发板外部中断
1 个回答
东软载波ESF0654 PDS开发板高级控制定时器AD16C4T
1 个回答
用串口调试助手为什么只能在hex模式接收发送而在文本模式不行
9 个回答
触摸芯片SC02B/SC04B在地砖灯的设计方案
1 个回答
相关文章
51单片机与蓝牙模块连接
0个评论
51单片机的硬件结构
0个评论
基于51单片机的无线遥控器制作
0个评论
51单片机 AD转换
0个评论
51单片机数码管递增显示
0个评论
如何实现对单片机寄存器的访问
0个评论
基于51单片机的指纹密码锁
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
51单片机
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
- //程序头函数
- #include <reg52.h>
- //显示函数
- //宏定义
- #define uint unsigned int
- #define uchar unsigned char
- #define Data_ADC0809 P1
-
- //管脚声明
- sbit LED_yanwu= P2^1;
- sbit baojing= P2^5;
- //ADC0809
- sbit ST=P3^3;
- sbit EOC=P3^6;
- sbit OE=P3^2;
- //按键
- sbit Key1=P2^6;
- sbit Key2=P2^7;
- sbit Key3=P3^7;
- signed char y; //浓度值全局变量
- uint c; //浓度值全局变量
- bit bdata flag=0;
- //co含量变量
- uchar nongdu;
- uchar yushe_yanwu=45;
- //按钮模式|
- uchar Mode=0;
- //函数声明
- extern uchar ADC0809();
- extern void Key();
- void delay(uint z)
- {
- uint i,j;
- for(i=0;i<z;i++)
- for(j=0;j<121;j++);
- }
- //ADC0809读取信息
- uchar ADC0809()
- {
- uchar yanwu_=0x00;
- //转化初始化
- ST=0;
- //开始转换
- ST=1;
- ST=0;
- //外部中断等待AD转换结束
- while(EOC==0)
- //读取转换的AD值
- OE=1;
- yanwu_=Data_ADC0809;
- OE=0;
- return yanwu_;
- }
- void Key()
- { //模式选择
- void write_com()
- if(Key1==0)
- {
- while(Key1==0);
- if(Mode>=3) Mode=0;
- else
- {
-
- }
- }
- if(Key2==0&&Mode!=0)
- {
- while(Key2==0);
- switch(Mode)
- {
- case 1:
- {
-
- yushe_yanwu++;
- if(yushe_yanwu>=255)
- yushe_yanwu=255;
- write_com(0x80+13);
- write_data(0x30+yushe_yanwu/100);
- write_data(0x30+yushe_yanwu%100/10);
- write_data(0x30+yushe_yanwu%10);
- break;
- }
- }
- }
- if(Key3==0&&Mode!=0)
- {
- while(Key3==0);
- switch(Mode)
- {
- case 1:
- {
- yushe_yanwu--;
- if(yushe_yanwu<=0)
- yushe_yanwu=0;
- write_data(0x30+yushe_yanwu%100/10);
- write_data(0x30+yushe_yanwu%10);
- break;
- }
- }
- }
- delay(200);
- }
- /*****************************************************************
- iic控制1602 lcd
- *****************************************************************/
- #include <reg51.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit SCL = P1^5;
- sbit SDA = P1^6;
- char ADDR = 0x7E;
- void delay(int ms);
- void IIC_start(void);
- void IIC_stop(void);
- void IIC_writeByte(char temp);
- void send_command(char comm);
- void send_data(char data1);
- void init_lcd(void);
- void clear_lcd(void);
- void print_lcd(int x, int y, char *str);
- void print_customer(int x, int y, char str[]);
- void main(){
- unsigned char table[]={0x10,0x06,0x09,0x08,0x08,0x09,0x06,0x00}; //×?·???
- unsigned char table1[]={
- 0x03,0x07,0x0f,0x1f,0x1f,0x1f,0x1f,0x1f,
- 0x18,0x1E,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
- 0x07,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
- 0x10,0x18,0x1c,0x1E,0x1E,0x1E,0x1E,0x1E,
- 0x0f,0x07,0x03,0x01,0x00,0x00,0x00,0x00,
- 0x1f,0x1f,0x1f,0x1f,0x1f,0x0f,0x07,0x01,
- 0x1f,0x1f,0x1f,0x1f,0x1f,0x1c,0x18,0x00,
- 0x1c,0x18,0x10,0x00,0x00,0x00,0x00,0x00
- };//????°?
- init_lcd();
- print_lcd(0,0,"Hello! >_<");
- print_lcd(0,1," I Love U -Gao W");
- //print_customer(0,0,table);
- while(1);
- }
- void delay(int ms){
- unsigned char y ;
- while(ms--){
- for(y = 0 ; y<250 ; y++){
- _nop_() ;
- _nop_() ;
- _nop_() ;
- _nop_() ;
- }
- }
- }
- void IIC_start(void){
- SDA=1;
- _nop_();
- SCL=1;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- SDA=0;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- SCL=0;
- }
- //????????
- void IIC_stop(void){
- SDA=0;
- _nop_();
- SCL=1;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- SDA=1;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- }
- void IIC_writeByte(char temp){
- char i;
- for(i=0;i<8;i++){
- SDA=(bit)(temp & 0x80) ;
- temp <<=1;
- _nop_();
- _nop_();
- SCL=1;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- SCL=0;
- }
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- SDA=1;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- SCL=1;
- _nop_();
- _nop_();
- _nop_();
- while(SDA);
- _nop_();
- SCL=0;
- }
- void send_command(char comm){
- char tmp;
- IIC_start();
- IIC_writeByte(ADDR);
- tmp = comm & 0xF0;
- tmp |= 0x0C; //RS = 0, RW = 0, EN = 1
- IIC_writeByte(tmp);
- delay(20);
- tmp &= 0xFB; //Make EN = 0
- IIC_writeByte(tmp);
- tmp = (comm & 0x0F) << 4 ;
- tmp |= 0x0C; //RS = 0, RW = 0, EN = 1
- IIC_writeByte(tmp);
- delay(20);
- tmp &= 0xFB; // Make EN = 0
- IIC_writeByte(tmp);
- //stop_8574();
- }
- void send_data(char data1){
- char tmp;
- IIC_start();
- IIC_writeByte(ADDR);
- tmp = data1 & 0xF0;
- tmp |= 0x0D; //RS = 0, RW = 0, EN = 1
- IIC_writeByte(tmp);
- delay(20);
- tmp &= 0xFB; //Make EN = 0
- IIC_writeByte(tmp);
- tmp = (data1 & 0x0F) << 4 ;
- tmp |= 0x0D; //RS = 0, RW = 0, EN = 1
- IIC_writeByte(tmp);
- delay(20);
- tmp &= 0xFB ; // Make EN = 0
- IIC_writeByte(tmp);
- }
- //LCD????"?
- void init_lcd(void){
- send_command(0x33);
- delay(50) ;
- send_command(0x32);
- delay(50) ;
- send_command(0x28);
- delay(50) ;
- send_command(0x0C);
- delay(50) ;
- send_command(0x06);
- delay(50) ;
- send_command(0x01);
- delay(50) ;
- }
- //Clear Screen
- void clear_lcd(void){
- send_command(0x01);
- }
- void print_lcd(int x, int y, char *str){
- char addr;
- if( x < 0){
- x = 0;
- }
- if(x > 15){
- x = 15;
- }
- if(y<0){
- y = 0;
- }
- if(y > 1){
- y = 1;
- }
- // Move cursor
- addr = 0x80 + 0x40 * y + x;
- send_command(addr);
- while (*str) {
- send_data(*str++);
- }
- }
- void print_customer(int x, int y, char *str){
- unsigned char i,tmp;
- for(i=0;i<8;i++){
- send_command(0x40+i);
- send_data(*str++);
- }
- }
- /****************************************************
- 结束
- ****************************************************/
- void main()
- {
- check_nongdu();
- check_nongdu();
- Init_lcd();
- while(1)
- {
- yanwu=ADC0809();
- check_nongdu();
- Key();
- if(Mode==0)
- {
- Display_lcd(yushe_yanwu,c,nongdu);
- if(nongdu>=yushe_yanwu)
- {
- LED_yanwu=0;
- baojing=0;
- }
- else
- {
- LED_yanwu=1;
- }
- if((nongdu<yushe_yanwu))
- {
- baojing=1;
- }
- }
- }
- }
复制代码一周热门 更多>