1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: What does the following lines of C source code mean?

  1. Jan 7, 2013 #1
    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.
    1. The problem statement, all variables and given/known data

    2. Relevant equations

    3. The attempt at a solution
  2. jcsd
  3. Jan 7, 2013 #2


    User Avatar
    Gold Member

    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.
  4. Jan 7, 2013 #3


    User Avatar

    Staff: Mentor

    As phinds points out, you must show your attempt first, before we can offer tutorial help.
  5. Jan 7, 2013 #4


    User Avatar
    Homework Helper

    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).
  6. Jan 8, 2013 #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.
  7. Jan 8, 2013 #6


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    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..


    Depending on the PIC..

  8. Jan 10, 2013 #7
    Thanks i appreciate the help!
  9. Jan 10, 2013 #8


    User Avatar
    Science Advisor

    I thought that looked more like assembly language than C!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook