標(biāo)題:
通過(guò)藍(lán)牙模塊將溫度數(shù)據(jù)傳遞給數(shù)碼管顯示程序咋寫(xiě)
[打印本頁(yè)]
作者:
zjt666
時(shí)間:
2023-4-9 09:16
標(biāo)題:
通過(guò)藍(lán)牙模塊將溫度數(shù)據(jù)傳遞給數(shù)碼管顯示程序咋寫(xiě)
求大佬
1681002946516..jpg
(1.3 MB, 下載次數(shù): 42)
下載附件
2023-4-9 09:15 上傳
作者:
xmcolong
時(shí)間:
2023-4-15 03:19
#include "HT66F0185.h"
#include "LCD.h"
#include "ntc.h"
#define CLED _pa3
#define BEEP _t1on
#define u8 unsigned char
#define u16 unsigned int
#define bps9600 12 //sys=8m
//#define bps9600 19 //sys=12m
volatile u8 recdata=0;
volatile u8 beeptime=0;
void delay_ms(u16 ms)
{
while(ms--)
{
GCC_DELAY(2000);//編譯器自帶延時(shí)指定個(gè)周期,在主頻8Mhz下,一個(gè)指令周期為0.5us
GCC_CLRWDT();
}
}
void UART_SendChar(u8 data)
{
if(_txif) //判斷發(fā)送數(shù)據(jù)寄存器為空
{
_txr_rxr=data; //寫(xiě)入TXR--------清標(biāo)志位TXIF,TXIF=1標(biāo)志TXR寫(xiě)入TSR,0標(biāo)志禁止寫(xiě)入TXR中已有數(shù)據(jù)
while(!_txif); //等待數(shù)據(jù)寫(xiě)入TSR
while(!_tidle); //等待數(shù)據(jù)傳輸結(jié)束
}
}
void pwminit()
{
_pac7=0;
_pa7=0;
_t1cp=1;//設(shè)置端口為定時(shí)器端口
_tm1c0=0x20;//clk=sys/16
_tm1c1=0xa8;//pwm模式 高電平有效 比較器P匹配清0
_tm1rpl=125;//f=sys/16/125=4k
_tm1rph=0;
_tm1al=62;//duty=62/125=49.6%
_tm1ah=0;
}
void main()
{
u8 temp;
u16 delaytime=0;
_wdtc=0xa8;//關(guān)閉看門(mén)狗
_csel=0;//
_cos=1;//
_acerl=0;//
//uart init
_pdc2=0;
_pd2=1;
_pdc1=1;
_pdpu1=1;
_ucr1=0x80;
_ucr2=0xc4;
_brg=bps9600;
_ure=1; //串口中斷使能
_emi=1;
ntcinit();
lcdinit();
pwminit();
_tbc=0xc4;//時(shí)基信號(hào) tbc=fsys/4 溢出周期:t=2^12/tbc=2.048ms
_tb0e=1;//允許時(shí)基中斷
_emi=1;//打開(kāi)總中斷
dispnum(0000);
while(1)
{
if(++delaytime>1000)
{
delaytime=0;
temp=GetTemp();
dispnum(temp);//顯示溫度
UART_SendChar(temp/10%10+'0');
UART_SendChar(temp%10+'0');
UART_SendChar(0X0D);
UART_SendChar(0X0A);
}
if(beeptime>0)
{
beeptime--;
BEEP=1;
}
else
{
BEEP=0;
}
delay_ms(1);
}
}
//時(shí)基中斷 2.048ms
DEFINE_ISR(tb0,0x1c)
{
LcdScan();
}
//中斷標(biāo)志位自動(dòng)清除
DEFINE_ISR(UART_Int,0x2c)
{
if(_rxif)//RXR寄存器中有數(shù)據(jù)
{
recdata=_txr_rxr;
if(recdata=='B')
{
beeptime=100;
}
}
}
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1