Created
June 2, 2012 06:15
-
-
Save CCodeWarrior/2856937 to your computer and use it in GitHub Desktop.
Demo for ADC implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ADCSET equ 0x0200 | |
RESULT equ 0x0100 | |
PORTBI equ 0x0010 | |
PORTB equ 0x0020 | |
DDRB equ 0x0030 | |
Periodo equ 0x0004 | |
CPReg equ 0x0008 | |
DCreg equ 0x000C | |
PolReg equ 0x001C | |
code | |
nop | |
nop | |
;configuracion de PORTB como salida | |
move r15, 0x00FF | |
out DDRB, r15 | |
;configuracion de PWM 12.2Khz, 8bits de resolucion | |
;polaridad normal | |
;auto secuencia de canal | |
move r0, 255 | |
out Periodo, r0 | |
move r0, 0 | |
out DCreg, r0 | |
move r0, 0x0035 | |
out CPReg, r0 | |
inicio: | |
move r0, 0x2000 ;modo singular canal 0 | |
out ADCSET, r0 | |
out RESULT, r15 | |
in r1, ADCSET | |
test r1, 0x0100 | |
jmpz $-2 ;espera de conversion de canal 0 | |
in r3, RESULT ;lectura de dato convertido | |
shr0 r3, 2 ; rotacion para alineacion con PWM de 8bits | |
out DCreg, r3 ; actualizacion de ciclo de trabajo | |
move r0, 0x3000 ;modo singular canal 1 | |
out ADCSET, r0 | |
out RESULT, r15 | |
in r1, ADCSET | |
test r1, 0x0100 | |
jmpz $-2 ;espera de conversion de canal 1 | |
in r2, RESULT ;lectura de dato convertido | |
shr0 r2, 2 ; rotacion para alineacion con PWM de 8bits | |
out DCreg, r2 ; actualizacion de ciclo de trabajo | |
sub r3, r2 | |
out PORTB, r3 | |
jmp inicio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment