What does the following lines of C source code mean?

Click For Summary

Discussion Overview

The discussion revolves around interpreting a segment of C source code, specifically regarding its functionality and configuration when executed on a CPU. The code involves manipulating registers and bits, likely in the context of embedded systems programming.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant requests an explanation of the CPU's actions when executing the provided C code, emphasizing the need for clarity on functionality and configuration.
  • Another participant suggests that the original poster should demonstrate some understanding or attempt before seeking help, implying that the question may lack depth.
  • Concerns are raised about the validity of the syntax "BSRbits.3," with one participant stating that it may not be a valid C construct and could lead to compilation issues.
  • There is speculation that "BSRbits" might represent a structure or union with a bit field, but the syntax used is questioned.
  • One participant interprets "INTCONbitsTMR0IE = 1" as enabling the timer0 interrupt and suggests that "TRISB = 0x00" configures Port B as outputs.
  • A recommendation is made to consult a PIC data sheet for further understanding of terms like "INTCONbits" and "PORTB," indicating that the code may be specific to PIC microcontrollers.
  • Another participant expresses confusion, noting that the code resembles assembly language more than C.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the validity of the syntax used in the code or its interpretation. Multiple viewpoints are presented regarding the nature of the code and its execution.

Contextual Notes

There is uncertainty regarding the specific definitions and structures involved in the code, particularly concerning the syntax and the context of the PIC microcontroller architecture.

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!
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
6K
Replies
1
Views
1K
Replies
2
Views
3K
Replies
2
Views
3K