[英]Reading input pin of PIC18F
我正在將交換機連接到PIC,我想閱讀該交換機。 我正在使用PIC18F4580。 如果輸入引腳為低電平,則它將打開連接到另一個引腳的LED,該引腳配置為輸出。 但是,LED一直亮着,並且開關按鈕無效。 這是我的代碼:
void main()
{
IRCF2_bit = 1; //Internal 8MHz Oscisllator Configuration
IRCF1_bit = 1;
IRCF0_bit = 0;
INTSRC_bit = 1;
PLLEN_bit = 0;
TRISD0_bit = 1; //Switch connected to D0 and pin configured as input
TRISD1_bit = 0; //LED connected to D1 and pin configured as output
PORTD.F1=0; //Turn off LED
while(1)
{
if (PORTD.F0==0)
{
//If Switch is pressed
delay_ms(100); //switch debounce
if (PORTD.F0==0)
{
PORTD.F1=1; //Turn on LED
}
else
{
PORTD.F1=0; //Turn off LED
}
}
}
}
我對如何做一無所知。 我已經為開關按鈕使用了上拉電阻,並且所有硬件都應該正確。 任何幫助深表感謝。
使用LAT(LATD)代替PORT(PORTD)對輸出進行更改
該程序永遠不會到達該語句
PORTD.F1=0; //Turn off LED
嘗試類似:
while(1)
{
if (PORTD.F0==0)
{
//If Switch is pressed
delay_ms(100); //switch debounce
PORTD.F1=1; //Turn on LED
}
else
{
PORTD.F1=0; //Turn off LED
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.