?? 程控源.c
字號:
/*******************************************************************************************************
程控源:key_s=P2_0; key_p=P2_1; key_n=P2_2;
開機時 電壓顯示:U-4.5
電流顯示:L-0.7
********************************************************************************************************/
#include <at89x52.h>
code unsigned char LedCode[13]= {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,0x3e,0x38,0x40}; //U .I. -
sbit key1=P2^0;
sbit key2=P2^1;
sbit key3=P2^2;
unsigned char s=0;
unsigned char Dout_U=90; //2格為1個單位
unsigned char Dout_I=140;
unsigned char u=45;
unsigned char i=70;
unsigned char DH,DL;
/*延時函數*/
void delay( unsigned int t)
{
unsigned int j;
for(j=0;j<t;j++ );
}
/*顯示函數*/
void xianshi_U(void)
{
DH=u/10;
DL=u%10;
P0 = LedCode[ 10 ]; P2_4 = 0; delay(300); P2_4=1;
P0 = LedCode[ 12 ]; P2_5 = 0; delay(300); P2_5=1;
P0 = LedCode[ DH ]|0x80; P2_6 = 0; delay(300); P2_6=1;
P0 = LedCode[ DL ]; P2_7 = 0; delay(300); P2_7=1;
}
void xianshi_L(void)
{
DH=i/10;
DL=i%10;
P0 = LedCode[ 11 ]; P2_4 = 0; delay(300); P2_4=1;
P0 = LedCode[ 12 ]; P2_5 = 0; delay(300); P2_5=1;
P0 = LedCode[ DH ]|0x80; P2_6 = 0; delay(300); P2_6=1;
P0 = LedCode[ DL ]; P2_7 = 0; delay(300); P2_7=1;
}
/**************電壓輸出*******************/
void dianya(void)
{
if(key2==0)
{
while(key2==0) xianshi_U();
if(u<50)
{
Dout_U=Dout_U+2;
u=u+1;
}
}
if(key3==0)
{
while(key3==0) xianshi_U();
if(u>0)
{
Dout_U=Dout_U-2;
u=u-1;
}
}
P3=Dout_U;
}
/**************電流輸出*******************/
void dianliu(void)
{
if(key2==0)
{
while(key2==0) xianshi_L();
if(i<80)
{
Dout_I=Dout_I+2;
i=i+1;
}
}
if(key3==0)
{
while(key3==0) xianshi_L();
if(i>0)
{
Dout_I=Dout_I-2;
i=i-1;
}
}
P3=Dout_I;
}
/******** 主程序 *******/
void main(void)
{
P2_3=0;
while(1)
{
if(key1==0)
{
if(s==0)
{
while(key1==0) xianshi_U();
}
if(s==1)
{
while(key1==0) xianshi_L();
}
s=!s;
}
if(s==0)
{
P2_3=0;
dianya();
xianshi_U();
}
if(s==1)
{
P2_3=1;
dianliu();
xianshi_L();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -