This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Need some help in programming 8051 with keil C

Hi 2 all,
Actually iam doing a project where i have to convert the analog voltage to digital and read it's output. I have done the program for generating the sclock and ss/ for ADC(Max187) and getting the serial 12 bit data output successfully....
But iam not able to convert this serial 12 bit data to parallel using 89C51 controller...
Can anyone help me by giving some hints or a sample program for it please....

Parents Reply Children
  • If having software SPI, you just toggle the clock for every bit, and pick up the state of the data line once for every bit. Then you use the shift operator to one-bit-at-a-time shift in the values in a 16-bit integer. After all 12 bits have been received, your integer have a value between 0 and 4095 (unless you managed to shift in the data from the wrong direction).

    The world is full of examples of software SPI. How many of these examples have you looked at?

  • I had a logic of reading the data on every negative edge of clock and storing it in A register. As i recieved 8bits i will transfer this data to R0 register and then to B. And then i clear A and read remaining 4bits and mov to port 0,2...

    But iam new to this keil programming. So iam not getting how to apply this logic...
    Thanks...

  • The shifting of serial bits from SPI to/from a parallel register is no different from shifting any other serial bits to/from a parallel register - so you can use any such example to see how it's done.

    There is nothing specific to the 8051 or Keil here - it is all just basic 'C' skills...

  • Just verify if you do want to transfer 8 bits to one register and then 4 bits to the next register, or if the data is sent in the bit order that you want to do the reverse - receive only 4 bits to the first register before then receiving the remaining 8 bits.

  • Actually i want just 4MSB bit's of that 12bit serial data to convert into parallel data...
    Thanks...

  • Now, why would you select a 12-bit ADC if you only want a 4-bit conversion?

    If having 4 bits and full range is 0 to 5V, then each step would represent 0,33V, so one tick up or down is more than the allowed tolerance for the 5V supply. 4 bits would also be unsuitable for measuring battery voltages, unless you don't measure relative to ground but have an offset voltage you measure against.