What does the following lines of C source code mean?

AI Thread Summary
The discussion focuses on interpreting specific lines of C source code related to microcontroller functionality. The code initializes a variable and manipulates various control registers, including enabling timer interrupts and configuring PORTB as output. There is confusion regarding the syntax of "BSRbits.3," which may not be valid in C, suggesting it could be a structure or union with bit fields. The participants recommend consulting a PIC data sheet for detailed information on the registers involved. Overall, the conversation emphasizes the need for a foundational understanding of the code and its context in microcontroller programming.
android5555
Messages
5
Reaction score
0
1. Explain what the CPU will do in terms of functuality and configuration when executing the C source code below:

unsigned char value = 0x91

1) BSR = 5;

2) BSRbits.3 = 1;

3) INTCONbitsTMR0IE = 1;

4) INTCON2bitsTMR0IP = 1;

5) TRISB = 0x00;

6) PORTB = 0x00;


Please can somebody help me with this question.
 
Physics news on Phys.org
you need to show some attempt on your own, else it doesn't really look like you are asking for "help" so much as just asking for the answer(s)

One thing I would say is that while it has been a long time since I've done any C programming, I don't think "BSRbits.3" is a valid C construct so on that one the CPU isn't likely to do anything at run-time because the compiler won't let it get that far.
 
android5555 said:
1. Explain what the CPU will do in terms of functuality and configuration when executing the C source code below:

unsigned char value = 0x91

1) BSR = 5;

2) BSRbits.3 = 1;

3) INTCONbitsTMR0IE = 1;

4) INTCON2bitsTMR0IP = 1;

5) TRISB = 0x00;

6) PORTB = 0x00;


Please can somebody help me with this question.


As phinds points out, you must show your attempt first, before we can offer tutorial help.
 
Looks like BSRbits is a structure or union with a bit field, but the syntax BSRbits.3 doesn't seem correct. It would help if you show the declaration for BSRbits (and the typedef if that is used).
 
I'm not sure if "BSRbits.3 = 1" is a valid C statement, but that is exactly what the question says. I think the "INTCONbitsTMR0IE = 1" statement means that the timer0 interrupt is enabled. From what i understand from "TRISB = 0x00" it should mean Port B is configured as outputs.
 
I recommend you download a PIC data sheet and search it for relevant words like "INTCONbits", "TMR0IE", "PORTB" etc. There are also numerous guides on the web to the common bits of a PIC.

BSR stands for Bank Select Register. The BSR maps in banks of RAM and registers. See page 42..

http://ww1.microchip.com/downloads/en/devicedoc/30412c.pdf

Depending on the PIC..

The lower nibble is used to select the peripheral register bank. The upper nibble is used to select the general purpose memory bank.
 
Thanks i appreciate the help!
 
I thought that looked more like assembly language than C!
 
Back
Top