[問題] 用c語言寫8051 腳踏車測速器
我試著想用8051寫一個腳踏車測速器
大概的設計是這樣:
使用at89c51晶片
用keil uVision3寫c語言
腳踏車車輪每轉一圈會經由Schmitt trigger送一個負源觸發到8051的pin12(外源中斷)
然後利用8051計算其周期而算出速率
再由8051的P2輸出二位數到兩個7447在到7段LED數字顯示器
現在Schmitt trigger與7447的部份都沒有問題
問題是我用keil uVision3寫的程式燒進去都不會WORK
(就連寫最簡單的跑馬燈也不WORK)
是不是我在寫C程式的時候少了些什麼?
請高手幫我看看
-----------------------------------------------------------------
#include <regx51.h>
int counter,i; //counter為計時器; i為輪胎圈數;
int a,b,c,d,e; //A作為總數值(速率) B輸出暫存 C十位數暫存 D個位數暫存 E延遲用變
數
float period,r,p; //period周期; r為輪胎半徑;
main()
{
//計時器
TMOD=0x00; //mode 0
TH0=(8192-1000)/12; //1000us=1ms
TL0=(8192-1000)%12;
TR0=1; //timer start
//中斷器
IE=0x83; // EX0=1; ET0=1; EA=1;
TCON=0x01; // 使外源中斷1為負源處發;
//速率計算and二位數顯示
a=0x00; //將速率設0
P2=a; //先使兩個七段都顯示0
for(e=0;e<3200;e++); //延遲
while(1)
{
r=0.0005; //設r為0.0005 km
p=period/1000/3600; //把周期單位改成hr
a=2*3.14*r/p; //計算出速率(km/hr)
if(a>99) a=99; //防暴表
c=a/10; //將總數除以10取商數得到十位
d=a%10; //將總數除以10取餘數得到個位
c=c<<4; //將十位數(二進制)左移4位數
d=d&0x0f; //將各位數的上面四位數清為零
b=c+d; //將十位及個位數合併成8BIT BCD
P2=b; //將有個位十位數的BCD碼由P2輸出
for(e=0;e<15000;e++); //延遲
}
}
void timer0_int(void)interrupt 1 //計時器中斷0的副程式
{
TH0=(8192-1000)/12;
TL0=(8192-1000)%12;
counter++;
}
void int0(void)interrupt 0 //外源中斷0副程式
{
i++;
if(i==1) counter=0; //開始計時
if(i==6) //取五圈的平均周期
{
period=counter/5; //周期單位為ms
i=0;
}
}
-----------------------------------------------------------------
謝謝...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.214.71
推
06/13 16:24, , 1F
06/13 16:24, 1F
推
06/13 17:58, , 2F
06/13 17:58, 2F
→
06/13 17:59, , 3F
06/13 17:59, 3F
→
06/13 19:22, , 4F
06/13 19:22, 4F
→
06/13 19:45, , 5F
06/13 19:45, 5F
→
06/13 19:46, , 6F
06/13 19:46, 6F
→
06/13 19:46, , 7F
06/13 19:46, 7F
→
06/13 19:46, , 8F
06/13 19:46, 8F
→
06/14 01:05, , 9F
06/14 01:05, 9F
→
06/14 01:08, , 10F
06/14 01:08, 10F
→
06/14 01:43, , 11F
06/14 01:43, 11F
推
06/14 01:56, , 12F
06/14 01:56, 12F
→
06/14 15:58, , 13F
06/14 15:58, 13F
→
06/14 21:03, , 14F
06/14 21:03, 14F
→
06/15 03:01, , 15F
06/15 03:01, 15F
→
06/15 03:01, , 16F
06/15 03:01, 16F
→
06/15 03:34, , 17F
06/15 03:34, 17F
噓
06/15 16:33, , 18F
06/15 16:33, 18F
推
06/16 16:01, , 19F
06/16 16:01, 19F
→
06/17 00:49, , 20F
06/17 00:49, 20F
→
06/17 00:50, , 21F
06/17 00:50, 21F
推
06/17 01:37, , 22F
06/17 01:37, 22F
→
06/17 20:25, , 23F
06/17 20:25, 23F
推
06/17 22:26, , 24F
06/17 22:26, 24F
推
06/17 23:39, , 25F
06/17 23:39, 25F
→
06/17 23:40, , 26F
06/17 23:40, 26F
→
06/17 23:41, , 27F
06/17 23:41, 27F
→
06/17 23:41, , 28F
06/17 23:41, 28F
推
06/17 23:44, , 29F
06/17 23:44, 29F
→
06/17 23:44, , 30F
06/17 23:44, 30F
→
06/17 23:44, , 31F
06/17 23:44, 31F
→
06/17 23:45, , 32F
06/17 23:45, 32F
→
06/17 23:45, , 33F
06/17 23:45, 33F
→
06/18 21:32, , 34F
06/18 21:32, 34F
→
06/18 21:51, , 35F
06/18 21:51, 35F
ASM 近期熱門文章
PTT數位生活區 即時熱門文章