English 中文(简体)
PIC18f452 港口聆听问题
原标题:PIC18f452 port listening issue

为什么这一法典发挥作用? 我所希望的是,当我发布一个顿的话,那是 port。

main
trisb=0
trisa=0xff
while true
if ra0<>0 then
portb = not portb
end if
wend .end
问题回答

我不敢确定什么;它是否是伪装?

Anyway, you need to trigger on the CHANGE from RA0 == 0 to RA0 == 1. As written, as long as RA0 == 1 then your PORTB will toggle every time through the loop.

C中的一个例子是:

int main(void)
{
    unsigned char bButtonValue = 0;

    TRISA = 0xFF;
    TRISB = 0x00;

    while (1)
    {
        if (RA0 != bButtonValue) 
        {
            bButtonValue = RA0;
            if (bButtonValue == 1)
            {
                 PORTB= ~PORTB;
            }
         }
     }
}

Keep in mind that for a real app, you would want to debounce the switch input (make sure it s stable for a few samples before triggering the change event.





相关问题
Parsing Twitter feeds in C

I m trying to figure out how to get the most recent latitude and longitude of a Twitter user (from the new Geo API data, ie the <geo:point> tag, you can see how they look like on my twitter user ...

Interfacing 45DB161 data flash with 89LP4052 controller

I am trying to interface the data flash with 89lp 4052 controller. Crysal used 11.0592 mhz. This controller has built in spi bus. I tried all combinations of CPHA AND CPOL. Tried mode 0 as well as ...

Circular buffer pointer irregularities

This is a follow up on this question: Display previously received UART values. After implementing a circular buffer on the microcontroller, it seems that there is a problem with the pointers. Sent ...

Steps to read data from ARM microcontroller port

I am having trouble reading serial data from ARM LPC2378 microcontroller. Will I have to use UART or any GPIO port can be used?? is ayone having c code for it??

Display previously received UART values

This should be easy to answer to anyone familiar with C. I want to display the previous values of a variable (receive register of a UART (RS-232) on a microcontroller) on an LCD. This is my current ...

clear code for counting from 0 to 255 using 8-bit datatype

I was wondering if there is a clean way of counting from 0 to 255 using an 8 bit datatype, something like: for(uint8_t i(0);i<=255;++i) { .... } This obviously will not work but it makes it ...

热门标签