競賽時(shí)間:5小時(shí) 題號(hào) 一 二 二 總分 配分 15分 30分 55分 100分 得分
功能簡述 通過競賽硬件平臺(tái)模擬小區(qū)自動(dòng)售水機(jī)的工作流程:通過按鍵控制售水機(jī)水流出和停止; 通過數(shù)碼管顯示費(fèi)率、出水量及總費(fèi)用;通過光敏電阻檢測(cè)環(huán)境亮度,在亮度過低的情況下, 自動(dòng)開燈。系統(tǒng)硬件電路主要由單片機(jī)控制電路、數(shù)碼管顯示電路、奶轉(zhuǎn)換電路及功能按 鍵組成。系統(tǒng)框圖如圖1所示:
圖1.系統(tǒng)框圖
I2C總線驅(qū)動(dòng)程序、CT107D考試平臺(tái)電路原理圖以及本題所涉及到的芯片數(shù)據(jù)手冊(cè), 可參考計(jì)算機(jī)上的電子文檔。程序流程圖及相關(guān)工程文件請(qǐng)以考生號(hào)命名,并保存在計(jì)算機(jī) 上的考生文件夾中(文件夾名為考生準(zhǔn)考證號(hào),文件夾位于Windows桌面上) 設(shè)計(jì)任務(wù)及要求 1.按鍵控制單元 設(shè)定按鍵S7為出水控制按鍵,當(dāng)S7按下后,售水機(jī)持續(xù)出水〈繼電器接通,指示 燈L10點(diǎn)亮設(shè)定按鍵S6為停水控制按鍵,當(dāng)S6按下后,停止出水〈繼電器斷開, 指示燈L10熄滅X 1.數(shù)碼管顯示單元 通過4位數(shù)碼管DS1顯示費(fèi)率,單位為元丨升,保留2位有效數(shù)字; 通過4位數(shù)碼管DS2顯示當(dāng)前出水總量(出水時(shí),單位為升)和總價(jià)(停止時(shí),單 位為元按下出水按鍵S7后,清除數(shù)碼管DS2顯示數(shù)據(jù),數(shù)碼管DS2實(shí)時(shí)顯示出水 量(保留兩位有效數(shù)字〕,在出水狀態(tài)下,再次按下S7,不會(huì)影響出水狀態(tài),直到按下停 止按鍵S6為止;按下停止出水按鍵S6后,數(shù)碼管DS2顯示總價(jià)(保留兩位有效數(shù)字X 例:當(dāng)S7按下后,數(shù)碼管示意圖如圖2所示:
圖之.售水機(jī)出水狀態(tài)數(shù)碼管顯示
當(dāng)按鍵86按下后,數(shù)碼管示意圖如圖3所示:
圖3^售水機(jī)出停水態(tài)數(shù)碼管顯示
3^入0轉(zhuǎn)換單元 通過光敏電阻RD1和AD轉(zhuǎn)換芯片PCF8591組成的亮度檢測(cè)電路〈亮度值轉(zhuǎn)換為PCF8591光敏電阻通道的電壓〕檢測(cè)環(huán)境亮度;當(dāng):PCF8591光敏電阻通道輸入電壓小 于1.25 V時(shí),L1點(diǎn)亮,大于1.25V時(shí),L1熄滅。 4^系統(tǒng)說明 1.假定水價(jià)為0.5元/升,出水速度為100毫升/秒; 1. 一次出水總量達(dá)到99.99L時(shí),繼電器自動(dòng)斷開,數(shù)碼管顯示DS2顯示價(jià)格。
項(xiàng)目名稱 得分 評(píng)卷人 電路設(shè)計(jì) 一.電路原理圖設(shè)計(jì) 根據(jù)設(shè)計(jì)任務(wù)要求,設(shè)計(jì)“接口電路”原理圖,并標(biāo)明元器件參數(shù);8CH只文件保存在 考生文件夾中(文件夾以考生的準(zhǔn)考證號(hào)命名〕。〔15分) 項(xiàng)目名稱 得分 評(píng)卷人 程序設(shè)計(jì) 二.程序編寫及流程圖繪制 1.畫出程序流程圖,保存在考生文件夾中。〔15分) 2^按照設(shè)計(jì)要求完成程序設(shè)計(jì)任務(wù),并將工程文件保存在考生文件夾中。〔15分) 項(xiàng)目名稱 得分 評(píng)卷人 硬件調(diào)試 三.硬件調(diào)試 將編譯通過的程序下載到
處理器芯片中,進(jìn)行硬件調(diào)試。 1.按鍵控制功能實(shí)現(xiàn)〔15分) 2^數(shù)碼管顯示功實(shí)現(xiàn)〔20分) 3^繼電器功能實(shí)現(xiàn)〔5分) 4^AD采集及LED控制功能實(shí)現(xiàn)〔15分)
參考程序 #include "reg52.h" #include "intrins.h" #define uchar unsigned char #define uint unsigned int
#define somenop {_nop_();_nop_();_nop_();_nop_();_nop_();} uchar code smg_du[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; uchar code smg_we[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; uchar code smg_du1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x7f}; //有小數(shù)點(diǎn)的段選 sbit SDA = P2^1; sbit SCL = P2^0; sbit s7=P3^0; sbit s6=P3^1;
uchar tflag,dspflag,qian,bai,shi,ge,qian1,bai1,shi1,ge1,num,temp,bb; uint t,aa,date;
void delayms(uint x) { uchar t; while(x--)for(t=0;t<120;t++); }
void keyscan() { if(s7==0) { delayms(10); if(s7==0) { P0=0x10;P2=0xa0;P2=0; TR0=1;num=1;t=0; while(!s7); } } if(s6==0) { delayms(10); if(s6==0) { date=t/2;TR0=0; P0=0;P2=0xa0;P2=0; num=2; TR0=1; while(!s6); } } }
void display(uchar we,uchar du) { P0 = 0xFF; //消影子 P2 |= 0xE0; P2 &= 0x1F;
P0 = smg_du[du]; P2 |= 0xE0; P2 &= 0x1F; P0 =smg_we[we]; P2 |= 0xC0; P2 &= 0x3F;
} ///////////////////////////////////////////////////////////////// void iic_start(void) { SDA = 1; _nop_(); SCL = 1; somenop; SDA = 0; somenop; SCL = 0; }
void iic_stop(void) { SDA = 0; _nop_(); SCL = 1; somenop; SDA = 1; }
void ack() { unsigned char i; SCL=1;somenop;while((SDA==1)&&(i<200))i++;SCL=0; }
void iic_sendbyte(unsigned char byt) { unsigned char i; for(i=0;i<8;i++) { if(byt&0x80) SDA = 1; else SDA = 0; somenop; SCL = 1; byt <<= 1; somenop; SCL = 0; } ack(); }
unsigned char iic_recbyte(void) { unsigned char da; unsigned char i; for(i=0;i<8;i++) { SCL = 1; somenop; da <<= 1; if(SDA) da |= 0x01; SCL = 0; somenop; } return da; }
unsigned char adc_pcf8591(void) { unsigned char temp;
iic_start(); iic_sendbyte(0x91); temp = iic_recbyte(); iic_stop();
return temp; } void init_pcf8591(void) { iic_start(); iic_sendbyte(0x90); iic_sendbyte(0x01); iic_stop(); delayms(10); } //////////////////////////////////////////////////////////////// void main() { P0=0xff;P2=0x80;P2=0; P0=0;P2=0xa0;P2=0; //關(guān)蜂鳴器 TMOD = 0x22; TH0 = 0x06; TL0 = 0x06; TH1 = 0x06; TL1 = 0x06; ET0 = 1; EA = 1; ET1=1;TR1=1; init_pcf8591();
while(1) { keyscan(); if(t==10000) { TR0=0; P0=0;P2=0xa0;P2=0; num=3; //超出標(biāo)志 TR0=1; } } }
void isr_t0(void) interrupt 1 //數(shù)碼管顯示 { tflag++; aa++; if(aa==400) //10ms t++ { aa=0; t++; if(t==10000) {
P0=0;P2=0xa0;P2=0; } qian=t/1000;bai=t%1000/100;shi=t%100/10;ge=t%10; } if(num==1) //計(jì)時(shí)標(biāo)志 { if(tflag == 4) //1ms 動(dòng)態(tài)顯示 { tflag = 0; dspflag++; if(dspflag == 7) dspflag = 0; if(dspflag==0) { P0 = 0xFF;P2 |= 0xE0;P2 &= 0x1F; P0=smg_du1[bai];P2 |= 0xE0;P2 &= 0x1F; P0 =smg_we[5];P2 |= 0xC0;P2 &= 0x3F; }
if(dspflag==1) display(6,shi); if(dspflag==2) display(7,ge); if(dspflag==3) display(4,qian); if(dspflag==4) { P0 = 0xFF;P2 |= 0xE0;P2 &= 0x1F; P0=smg_du1[0];P2 |= 0xE0;P2 &= 0x1F; P0 =smg_we[1];P2 |= 0xC0;P2 &= 0x3F; } if(dspflag==5) display(2,5); if(dspflag==6) display(3,0); } } if(num==2) //算費(fèi)標(biāo)志 { if(tflag == 4) //1ms { tflag = 0;dspflag++; if(dspflag == 7) { dspflag = 0; qian1=date/1000;bai1=date%1000/100;shi1=date%100/10;ge1=date%10; } if(dspflag==0) { P0 = 0xFF;P2 |= 0xE0;P2 &= 0x1F; P0 = smg_du1[bai1];P2 |= 0xE0;P2 &= 0x1F; P0 =smg_we[5];P2 |= 0xC0;P2 &= 0x3F; } if(dspflag==1) display(6,shi1); if(dspflag==2) display(7,ge1); if(dspflag==3) display(4,qian1); if(dspflag==4) { P0 = 0xFF;P2 |= 0xE0;P2 &= 0x1F; P0=smg_du1[0];P2 |= 0xE0;P2 &= 0x1F; P0 =smg_we[1];P2 |= 0xC0;P2 &= 0x3F; } if(dspflag==5) display(2,5); if(dspflag==6) display(3,0); } } if(num==3) { if(tflag == 4) //100ms { tflag = 0;dspflag++; if(dspflag == 7) { dspflag = 0; } if(dspflag==0) { P0 = 0xFF;P2 |= 0xE0;P2 &= 0x1F; P0 = smg_du1[9];P2 |= 0xE0; P2 &= 0x1F; P0 =smg_we[5];P2 |= 0xC0;P2 &= 0x3F; } if(dspflag==1) display(6,9); if(dspflag==2) display(7,9); if(dspflag==3) display(4,4); if(dspflag==4) { P0 = 0xFF;P2 |= 0xE0;P2 &= 0x1F; P0=smg_du1[0];P2 |= 0xE0;P2 &= 0x1F; P0 =smg_we[1];P2 |= 0xC0;P2 &= 0x3F; } if(dspflag==5) display(2,5); if(dspflag==6) display(3,0); } } }
void T1_timer() interrupt 3 //LED PCF8591 { bb++; if(bb==8) { bb=0; temp=adc_pcf8591(); if(temp<64) { P0=0xfe;P2=0x80;P2=0; } if(temp>64) { P0=0xff;P2=0x80;P2=0; } } }
|