|
步驟及現(xiàn)象:程序下載前,選擇stc-isp的IRC頻率:12MHz。程序下載后,通過改變開發(fā)板杜邦線的連接方式實現(xiàn)不同功能。
dianweiqi.jpg (3.1 MB, 下載次數(shù): 71)
下載附件
電位器現(xiàn)象.jpg
2019-10-9 16:31 上傳
(1)電位器旋鈕可調(diào)電壓:
用杜邦線或跳線帽把AIN0與RAD短接。這時數(shù)碼管前三位顯示一個十進制數(shù)字,當擰動電位器時數(shù)字也跟著變化,變化范圍為0.00~5.00。
(2)光敏電阻電壓:
用杜邦線把AIN0與J13右側(cè)兩個排針同時短接。這時數(shù)碼管前三位顯示一個十進制數(shù)字,通過遮擋光敏電阻RL或用手電筒照射光敏電阻RL,數(shù)碼管顯示數(shù)字改變,變化范圍0.00~5.00。
(3)熱敏電阻電壓:
用杜邦線把AIN0與J13左側(cè)兩個排針同時短接。這時數(shù)碼管前三位顯示一個十進制數(shù)字,通過用手觸摸熱敏電阻NTC,數(shù)碼管顯示數(shù)字改變,變化范圍0.00~5.00。
#include "stc8.h"
#include "pcf8591_i2c.h"
#include "hc595.h"
void main()
{
int dat;
while(1)
{
dat = ((int)Pcf8591_ReadAD())/51.0*100; // 讀取ad值
display(0,dat/100); // 數(shù)據(jù)在數(shù)碼管上顯示
display(0,19);
display(1,dat%100/10);
display(2,dat%10);
}
}
- #include "hc595.h"
- #include "stc8.h"
- #include <intrins.h>
- sbit P_HC595_SRCLK = P3^5; // 移位時鐘
- sbit P_HC595_RCLK = P3^4; // 存儲時鐘
- sbit P_HC595_SER = P3^7; // 數(shù)據(jù)輸入端
- // 段選:dp、g、f、e、d、c、b、a
- unsigned char const LedData[]=
- {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xFF , 0x00, 0xbf,0x7f,0x89};
- // "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" "全滅" "全亮" "-" "." "H"
- // 位選:CS1、CS2、CS3、CS4、CS5、CS6、CS7、CS8
- unsigned char const LedPos[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- /***** 延時函數(shù),xms是多少就延時多少毫秒 *****/
- void sDelay_ms(unsigned int xms) // 晶振:12MHz
- {
- unsigned int i, j;
- for(i=xms;i>0;i--)
- for(j=921;j>0;j--);
- }
- /*************************************************
- * 函數(shù)名:Send_595
- * 描述 :hc595發(fā)送一個字節(jié)數(shù)據(jù)
- * 參數(shù) :dat (位選或段選)
- * 返回值:無
- * 調(diào)用 :內(nèi)部調(diào)用
- *************************************************/
- void Send_595(unsigned char dat)
- {
- unsigned char i;
- for(i=0; i<8; i++)
- {
- dat <<= 1;
- P_HC595_SER = CY;
- P_HC595_SRCLK = 0; // SH_CP產(chǎn)生一個上升沿,數(shù)據(jù)移位
- _nop_();
- P_HC595_SRCLK = 1;
- }
- }
- /*************************************************
- * 函數(shù)名:display
- * 描述 :pos位數(shù)碼管顯示數(shù)字dat
- * 參數(shù) :pos,dat
- * 返回值:無
- * 調(diào)用 :外部調(diào)用
- *************************************************/
- void display(unsigned char pos,unsigned char dat)
- {
- Send_595(LedPos[pos]); // 發(fā)送位選
- Send_595(LedData[dat]); // 發(fā)送段選
- P_HC595_RCLK = 0; // ST_CP產(chǎn)生一個上升沿,數(shù)據(jù)并口輸出
- _nop_();
- P_HC595_RCLK = 1;
- sDelay_ms(5); // 延時5ms
- }
復(fù)制代碼
|
評分
-
查看全部評分
|