alfred 發表於 27-6-2007 00:24:54

8051 C PROGRAMMING

早前我上了8051初及中班, 本人對此很感興趣, 但是組合語言來控制硬件確實需要很長的時間發展及學習,所以我開始試用C語言,但剛開始便出現一個問題,PROGRAM如下:
問題在於無論P3.2腳是OPEN還是SHORT, 都是令燈亮著, 如果用組合語言的話可以控制到燈的亮著與關閉? 請教各路高手指點.

#define _TEST_C_
#include "reg51.h"
#include "test.h"
sbit P10 = P1^0; // 燈腳
sbit K1 = P3^2; // 開關掣

void main(void)
{

if(K1)
{
   P10 = 0;
}
}

VR2XPO 發表於 27-6-2007 07:37:17

I hope it usefull

hello, I am vr2xpo.
I think there are some problems that is "no else" and "no looping".
The conpcert must be:
" If K1 is High then P10 is OFF else P10 is ON, go back to check "
so the program maybe follow:

while(1)
    {   If(K1)
         { // your program
         }
         else
         { P10=1;
         }
   }

I hope it no mistake ^_^

alfred 發表於 27-6-2007 22:35:39

謝謝你的回覆, 最重要是我每一次開或關都做一次reset. 但是結果不變.

(你的方法也試過, 開關仍然不變. ) 請問實驗板及Insight Me-52hu 有什麼需要注意的地方嗎??

alfred 發表於 28-6-2007 01:24:54

足足攪左四個小時, 原來EMULATOR 插位鬆左少少, 令P2及P3一部份PORTS位 感應好差, 氣死我了,

再此先謝謝各位的幫忙.
頁: [1]
查看完整版本: 8051 C PROGRAMMING