单片机Word文档格式.docx
- 文档编号:15392669
- 上传时间:2022-10-29
- 格式:DOCX
- 页数:31
- 大小:22.06KB
单片机Word文档格式.docx
《单片机Word文档格式.docx》由会员分享,可在线阅读,更多相关《单片机Word文档格式.docx(31页珍藏版)》请在冰豆网上搜索。
#defineSW_DA_ADP3_0//0->
DA1->
AD
#defineSW_DA_VALUE0
#defineSW_AD_VALUE1
//AD转换定时器中断次数0~19
ucharT_AD_CONVERT_INT=0;
//DA值
floatDA_value_float=5.0;
ucharDA_value_now=255;
//单位为255分之1
//AD值
ucharAD_value_now=127;
//数码管
ucharLEDS_TABLE[]={0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b,0x7e};
//commonpart
#defineHIGH1
#defineLOW0
#defineTRUE1
#defineFALSE0
#defineZERO0
#defineMSB0x80
#defineLSB0x01
//max7219part
#defineDECODE_MODE0x09
#defineINTENSITY0x0A
#defineSCAN_LIMIT0x0B
#defineSHUT_DOWN0x0C
#defineDISPLAY_TEST0x0F
//pindefined
/***********************************************************************/
//changethispartatdifferentboard
sbitLOAD=P1^4;
//MAX7219Load-DataInput:
risingedgepin12
sbitDIN=P1^5;
//MAX7219Serial-DataInput:
risingedgepin1
sbitCLK=P1^6;
//MAX7219Serial-ClockInput:
maximum10MHzpin13
//functiondefine
voidWrite_Max7219_byte(unsignedchartemp);
//writemax7219abyte
voidWrite_Max7219(unsignedcharaddress,unsignedchardat);
//writemax7219commandanddata
voidInit_Max7219(void);
//Initizemax7219
//testprogramdisplayfrom1~8
/*voidmain(void)
{
unsignedchari;
Init_Max7219();
while(TRUE)
{
for(i=1;
i<
9;
i++)
Write_Max7219(i,i);
}
}*/
voidWrite_Max7219_byte(unsignedchartemp)
for(i=0;
8;
CLK=LOW;
DIN=(bit)(temp&
MSB);
temp=temp<
<
1;
CLK=HIGH;
}
voidWrite_Max7219(unsignedcharaddress,unsignedchardat)
LOAD=LOW;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
LOAD=HIGH;
voidInit_Max7219(void)
Write_Max7219(SHUT_DOWN,0x01);
//NormalOperationXXXXXXX1ShutdownModeXXXXXXXX0
Write_Max7219(DISPLAY_TEST,0x00);
//NormalOperationXXXXXXX0DisplayTestModeXXXXXXXX1
Write_Max7219(DECODE_MODE,0x00);
//DecodeModeSelectD7~D01Bdecode0Nodecode
Write_Max7219(SCAN_LIMIT,0x03);
//SCANLIMIT0~70xX0~0xX7
Write_Max7219(INTENSITY,0x04);
//SetIntensity0xX0~0xXf
voiddelay10ms(void)
{
unsignedchari,j,k;
for(i=5;
i>
0;
i--)
for(j=4;
j>
j--)
for(k=248;
k>
k--);
}
voiddelay(uintt)
while(t--);
voidDisplay_DA()
floatvalue_temp=DA_value_float;
Write_Max7219(1,LEDS_TABLE[(uint)value_temp]+0x80);
Write_Max7219(2,LEDS_TABLE[((uint)(value_temp*10))%10]);
Write_Max7219(3,LEDS_TABLE[((uint)(value_temp*100))%10]);
Write_Max7219(4,LEDS_TABLE[10]);
voidDisplay_AD()
floatvalue_temp=((float)(5*((uint)AD_value_now)))/255.0;
Write_Max7219(1,LEDS_TABLE[(uint)value_temp]+0x80);
//完成AD转换并输出到DA口
voidAD_Convert(void)
chartemp=0;
uintvalue=0;
for(temp=7;
temp>
=0;
temp--)
{
COMP_IN=1;
value=value+(1<
temp);
DA_OUT=value;
delay(5);
if(COMP_IN==1)//比较结果为1==>
外部输入电压(AD电压)较高
{}
else
value=value-(1<
}
DA_OUT=value;
AD_value_now=value;
voidKey_Pressed(ucharkey)
switch(key)
case1:
DA_value_float+=1.0;
if((uint)DA_value_float>
=6.0)DA_value_float=DA_value_float-6.0;
//6.06.0
break;
case2:
DA_value_float+=0.1;
if(((uint)(DA_value_float*10))%10==0)DA_value_float=DA_value_float-1.0;
case3:
DA_value_float+=0.01;
if(((uint)(DA_value_float*100))%10==0)DA_value_float=DA_value_float-0.1;
case4:
if(DA_value_float>
5)DA_value_float=5;
DA_value_now=(uint)(DA_value_float*51);
DA_OUT=DA_value_now;
voidtimer0(void)interrupt1
TR0=0;
if(SW_DA_AD==SW_DA_VALUE)//DA
Display_DA();
else//AD
Display_AD();
TH0=0;
TL0=0;
TR0=1;
//每20次定时器中断进行一次AD转换
voidtimer1(void)interrupt3
T_AD_CONVERT_INT++;
if(T_AD_CONVERT_INT>
=20)
AD_Convert();
T_AD_CONVERT_INT=0;
TH0=159;
TL0=88;
voidmain()
//4个按键的按键次数(10MS的次数)
charBTN_T_1=13;
charBTN_T_2=13;
charBTN_T_3=13;
charBTN_T_4=13;
EA=0;
//设置定时器和中断
TMOD=0x11;
PT0=1;
PT1=1;
ET0=1;
ET1=1;
//25毫秒的定时刷新单
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机