What does the following lines of C source code mean?

In summary, the CPU will run the C code below and will do so with 5 BSR bits set to 1, 1 BSR bits set to 3, and 1 INTCON bit set to 1. Additionally, the CPU will enable timer0 and set Port B to be outputs.
  • #1
android5555
5
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
  • #2
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.
 
  • #3
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.
 
  • #4
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).
 
  • #5
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.
 
  • #6
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.
 
  • #7
Thanks i appreciate the help!
 
  • #8
I thought that looked more like assembly language than C!
 

What does the following lines of C source code mean?

The following lines of C source code are instructions that tell the computer what to do. They are written in the C programming language, which is used to create software and applications.

What is the purpose of writing code in a specific programming language like C?

The purpose of writing code in a specific programming language is to communicate with the computer and give it instructions to perform specific tasks. Each programming language has its own syntax and rules for writing code.

Why is it important to follow proper syntax when writing code?

Proper syntax is important because it ensures that the computer can understand and execute the code correctly. If there are errors in the syntax, the code will not work as intended or may not work at all.

What does the "C" in C programming language stand for?

The "C" in C programming language stands for the language's creator, Dennis Ritchie, who developed it at Bell Labs in the 1970s. It is a high-level, general-purpose programming language that is widely used in software development.

Can anyone learn to code in C?

Yes, anyone can learn to code in C, as well as in any other programming language. It may require dedication, practice, and patience, but with the right resources and effort, anyone can become proficient in C programming.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
301
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
0
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
751
  • Programming and Computer Science
Replies
3
Views
879
Back
Top