Vous êtes sur la page 1sur 2

$regfile = "m328pdef.

dat" 'indica al compilador


el dispositivo a usar
$crystal = 16000000 'la frecuencia del
reloj (16MHz)
'$hwstack = 32
'$swtack = 10
'$framesize = 16

Dim V1 As Word
Dim V2 As Word
Dim S As Bit
Dim Error As Integer

Config Portb = Output 'Configura el puerto b


como salida
Config Adc = Single , Prescaler = Auto , Reference = Avcc 'Configura el conversor
adc del atmega de modo individual
Start Adc
'Enciende el ADC

Config Timer1 = Counter , Prescale = 1024 , Clear Timer = 1


'especifiado por Compare1A
Timer1 = 0 'inicializa el timer1
en cero.
S = 0

On Compare1a Tiempo ' Tiempo es el LABEL a


la cual debe saltar cuando de tiene una interrupcion

'Calcular el tiempo de muestro T:


' 1 segundo = 16`000000/1024 =15625
'Para un T=0.5 s ' 0.5 SEGUNDOS=0.5*15625==7812.5=H1E85
Compare1a = &H1E85
Enable Compare1a 'Habilita la
interrupcion por comparacion de timer1
Enable Interrupts 'Habilita las
interrupciones en general

Do
Loop
End 'final del programa

'Rutina de interrrupcion (actualizar salida)

Tiempo:
Timer1 = 0
V1 = Getadc(0)
V2 = Getadc(1)
Error = V1 - V2
If S = 0 Then
If Error >= -4 Then
Portb.0 = 1
Else
Portb.0 = 0
S = 1
End If
End If
If S = 1 Then
If Error >= 4 Then
Portb.0 = 1
S = 0
Else
Portb.0 = 0
End If
End If

Return

Vous aimerez peut-être aussi