开发者

Global Variable Pointer to array in Sourceboost C

开发者 https://www.devze.com 2023-04-11 23:44 出处:网络
I declared these global variables: volatile unsigned char BUFFER[7]={0,0,0,0,0,0,0};//to get all data volatile unsigned char *PTR=&BUFFER[0];//points t开发者_开发百科o start address

I declared these global variables:

volatile unsigned char BUFFER[7]={0,0,0,0,0,0,0};//to get all data
volatile unsigned char *PTR=&BUFFER[0];//points t开发者_开发百科o start address

Inside the Microchip PIC interrupt function, the pointer reads the UART register and deference it to BUFFER[] array according to my code:

*PTR=rcreg;
PTR++;

I then check the data in function main():

for(i=0;i<3;i++){
    if(BUFFER[i]==DATA[i]){
        k++;
        if(k==2){LED_On();}
    }
}

and set ptr to point at the start address of BUFFER[]

ptr=BUFFER;

Question: Is this the best way and correct way to read data in the register? How can I use pointer in interrupt function?

Thank you for your kind attention and help in advance!


You may want to consider implementing a lock-free circular buffer to transfer data between the ISR and main():
Circular lock-free buffer
Non-blocking algorithm

0

精彩评论

暂无评论...
验证码 换一张
取 消