adc problem

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi.. i have atmega16 and i have connected a potentiometer on the adc channel0 and want to see the converted or digital data on the computer
so i have made a program in which the adc output is transmitted serially to pc.. but i think there is a problem in the code... can any1 plz rectify it...??

note: asynchronous mode, baud rate 9600, parity bit none, 8 bit character size, division factor 8, stop bit 1.

Quote:

clr r23
out $1a,r23 // port a input
out $07,r23 //adcmux
ldi r16,$85
out $06,r16 //adscra
ldi r25,$ff
out $11,r25 //port d as output or txd as output
out $20,r23 //ubrrh data
ldi r17,$16
out $09,r17 //ubrrl data (16)h or (22)d for baud rate 9600
clr r18
out $0b,r18 //ucsra data
ldi r19,$08
out $0a,r19 //ucsrb data
ldi r20,$86
out $20,r20 //ucsrc data

next:
sbis $0b,5 //checking for udre
rjmp next
sbi $06,6 //set bit start conversion in adcsra
check: sbis $06,4 // checking for adif in adcsra
rjmp check
in r27,$04 //read the data from adcl
in r29,$05
out $0c,r27 // send the data to udr
sbi $06,4 // set bit adif (reseting the bit actually)
jmp next //repeating