|
我想設(shè)置兩個值,來保存led的值,讓輸出電壓的時候LED正常顯示設(shè)置的電壓值,該怎么設(shè)置這兩個數(shù)
捕獲3 (2).PNG (50.4 KB, 下載次數(shù): 50)
下載附件
2022-5-10 12:25 上傳
單片機(jī)源程序如下:
#include<math.h>
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
char led[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
char led1[]={0x3f,0x06,0x5b,0x4f,0xe66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit P3_7=P3^7; //加鍵
sbit P3_6=P3^6; //減鍵
sbit P3_1=P3^1;
sbit P3_0=P3^0;
sbit P3_4=P3^4; //模式選擇(設(shè)置輸出電壓值模式or電壓輸出模式)
uchar set=50,tj=0;
void delay (unsigned int time)
{
unsigned j;
for (;time>0;time--)
for(j=0;j<125;j++) ;
}
void main ()
{
while (1)
{
if(P3_4==0)
{ tj=!tj; while(P3_4==0) ; }
if(tj==0) //設(shè)置輸出電壓
{
//掃描按鍵1
if(P3_7==0)
{
delay(10); // 摁鍵消抖
if(P3_7==0)
{
set++;
if(set>99) set=99; // 設(shè)置顯示最大值
while(P3_7==0) // 等待按鍵松開
;
}
}
//掃描按鍵2
if(P3_6==0)
{
delay(10); // 摁鍵消抖
if(P3_6==0)
{
set--;
if(set<0) set=0 ; // 設(shè)置顯示最小值
while(P3_6==0) // 等待按鍵松開
;
}
}
//顯示兩位數(shù)碼管
P3_0=0; P3_1=1;
P0=led[set/10];
delay(50) ;
P3_0=1; P3_1=0;
P0=led1[set%10];
delay(50) ;
}
else{
P2=(float)set*2.56 ; //輸出算法
// P2=25.6;
}
}
}
|
|