Paso 9: código
Cuando programar el Atmega, también debe deshabilitar el JTAG en la fusebits y configurar el oscilador interno hasta 8MHz.
El código se ajusta a un Atmega16 pero usaba un Atmega32 como quiero añadir algunas características adicionales más adelante.
$regfile = "m32def.dat"
$crystal = 8000000
$baud = 9600
Config Serialin = tamponada, tamaño = 255
Config Serialout = tamponada, Size = 100
Config Graphlcd = 240 * 128, Puerto de datos = Porta, Controlport = Portc, Ce = 5, Cd = 4, Wr = 7, Rd = 6, Reset = 2, Fs = 3, modo = 8
Config Scl = Portc.0
Config Sda = Portc.1
Cha Alias Pind.3
CHB Alias Pind.4
config Cha = entrada
Config Chb = entrada
Const Ds1307w = & HD0 ' escribir DS1307
Const Ds1307r = & HD1 ' leer ds1307
Const Adsecs = & H00 ' Dirección segundos
Administradores de const = & H01 ' Dirección minutos
Dim cuenta como Byte
Dim yo como Byte
Dim J como Byte
Dim Pos como Byte
Dim Oldpos como Byte
Dim Maxpos como Byte
Como Byte DIM estado
Volumen tenue como Byte
Dim Temp como Byte
Dim Uart_in como Byte
Dim Uart_buffer como Byte
Dim horas como Byte
Dim minutos como Byte
Dim segundos como Byte
Dim longitud como Byte
Boxx DIM como Byte
Dim Boxx2 como Byte
Dim Tube(4) como Byte
X DIM como Byte
Dim Uart_in_str como String * 255
Dim estacionario como cadena * 60
Dim título como cadena * 60
Dim Station_pos como Byte
Dim Title_pos como Byte
Dim puntero como Byte
Dim Station_length como Byte
Dim Title_length como Byte
Dim Temp_str como cadena * 4
Dim Volumestr como cadena * 3
Dim Station(20) como cadena * 30
De Int0 0int
Habilitar la Int0
Habilitar interrupciones
' Set Chb
En Int1 1int,
Permiten Int1
Habilitar interrupciones
Esperar 1
CLS
Init:
Showpic 0, 0, Intro
Caja (115, 90)-(200, 104), 255
Para I = 118 de 194 paso 4
J = I + 3
Boxfill (i, 92)-(j, 102), 255
Esperar 3
Siguiente
Imprimir Chr (13)
Esperar 2
Imprimir "mpc claro"
Para I = 0 a 3
Estacionario = Lookupstr (i, Tunerlist2)
Imprimir "mpc agregar"; Estacionario
Siguiente
Imprimir "mpc volumen 50"
Imprimir "mpc play"
Volumen = 20
GoSub Empty_buffer
I = 1
Count = 1
Principal:
Estado = I
CLS
Si estado = 1 Then Goto Radio
Si estado = 2 Goto Tuning
Si estado = 3 Then Goto Vol
Si estado = 4 Goto configuración
Radio:
Maxpos = 6
POS = 1
Oldpos = 1
Boxx = 0
Boxx2 = 40
Showpic 0, 88, juego
Showpic 40, 88, pausa
Showpic 80, 88, Stopp
Showpic 120, 88, volumen
Showpic 160, 88, sintonizador
Showpic 200, 88, reloj
Caja de (0, 88)-(40, 127), 255
Hacer
Si me <> Estado entonces Goto principal
Si Pos <> Oldpos luego
Caja (boxx, 88)-(boxx2, 127), 0
Boxx = Pos - 1
Boxx = Boxx * 40
Boxx2 = Boxx + 40
Caja (boxx, 88)-(boxx2, 127), 255
Oldpos = Pos
End If
Imprimir "Eco"; Chr(34); "currentsong"; Chr(34); " | NC localhost 6600 | grep -e "; Chr(34); «^ Título: "; Chr(34); " -e " ; Chr(34); «^ Nombre: "; Chr(34); ">/dev/tts/0"; Chr (13)
Waitms 500
GoSub Getuart
Analizador de GoSub
Texto de CLS
Localizar 5, 1
Estacionario de LCD
Ubicar 8, 1
Título de LCD
GoSub Readclock
Lazo
Tuning:
CLS
Count = 1
Hacer
Texto de CLS
Si me <> Estado entonces Goto principal
GoSub Readclock
Para J = 1 a 4
Station(j) = Lookupstr (j, Tunerlist)
Siguiente
J = cuenta
Localizar 5, 5
LCD Station(j)
J = cuenta + 1
Localizar 6, 5
LCD Station(j)
J = cuenta + 2
Ubicar 7, 5
LCD Station(j)
Waitms 500
Lazo
Vol:
CLS
Hacer
GoSub Readclock
Si me <> Estado entonces Goto principal
Imprimir "Eco"; Chr(34); "estado"; Chr(34); " | NC localhost 6600 | grep -e "; Chr(34); «^ volumen: "; Chr(34); ">/dev/tts/0"; Chr (13)
Waitms 100
GoSub Getuart
GoSub Volumeparser
Texto de CLS
Localizar 6, 10
Volumen = Val(volumestr)
LCD "volumen:"; Volumen
Lazo
Configuración:
J = 1
Si J = 1 entonces cuenta = cuenta más horas = min
CLS
Hacer
CLS
Si me <> Estado entonces Goto principal
' Gosub Readclock
Si J = 1 entonces = horas minutos otra cuenta = cuenta
Tube(2) = minutos / 10 ' divide las horas y minutos en
Temp = Tube(2) * 10 4 dígitos para que puede ser aparezca
Tube(1) = minutos - temperatura
Tube(4) = horas / 10
Temp = Tube(4) * 10
Tube(3) = horas - Temp
Temp = Tube(4)
X = 48
GoSub Clockpic
Temp = Tube(3)
X = 72
GoSub Clockpic
Temp = 11
X = 96
GoSub Clockpic
Temp = Tube(2)
X = 120
GoSub Clockpic
Temp = Tube(1)
X = 144
GoSub Clockpic
Ubicar el 8, 8
LCD
Waitms 100
Lazo
Final
0int:
Si I = 1 y Pos = 1 entonces Imprimir "mpc play"
Si I = 1 y Pos = 2 entonces Imprimir "mpc pausa"
Si I = 1 y Pos = 3 entonces Imprimir "mpc stop"
Si I = 1 y Pos = 4 entonces = 3
Si I = 1 y Pos = 6 entonces = 4
Si estado = 2 entonces
Imprimir "mpc play"; Conde
I = 1
End If
Si I = 1 y Pos = 5 entonces I = 2
Waitms 100
Si estado = 3 entonces I = 1
Si I = 4 y J = 2 entonces
GoSub Setclock
I = 1
End If
Si I = 4 y J = 1 entonces
GoSub Setclock
J = 2
End If
Volver
1int:
1 Waitms
Si Cha = 1 y I <> 3 entonces
Si Chb = 0 entonces Incr cuenta cuenta de Decr otra cosa
End If
Si Cha = 1 y I = 3 entonces
Si Chb = 0 entonces Imprimir "mpc + 5"Else Print "mpc volumen -5"
End If
Pos = cuenta
Si Pos > Maxpos entonces Pos = Maxpos
Si Pos < 1 entonces Pos = 1
Volver
Getuart:
Uart_in_str = ""
Hacer
Uart_buffer = Ischarwaiting()
Si Uart_buffer > 0 entonces
Uart_in = Inkey()
Si Len(uart_in_str) < 254 entonces Uart_in_str = Uart_in_str + Chr(uart_in)
Si Len(uart_in_str) = 254 entonces Uart_in_str = Uart_in_str + Chr (13)
End If
Bucle hasta Uart_buffer = 0
GoSub Empty_buffer
Volver
Volumeparser:
Volumestr = ""
Temp = Instr (uart_in_str, "volumen:")
Temp = Temp + 8
Volumestr = Mid (uart_in_str, Temp, 3)
Volver
Analizador sintáctico:
Estacionario = ""
Title = ""
Station_pos = Instr (uart_in_str, "nombre:")
Title_pos = Instr (uart_in_str, "Título:")
Station_pos = Station_pos + 6
Longitud = 0
Hacer
Longitud de incr
Puntero = Station_pos + longitud
Temp_str = Mid (uart_in_str, puntero, 1)
Bucle hasta Temp_str = Chr (13) o Temp_str = ""
Si longitud > 60 entonces longitud = 60
Estacionario = Mid (uart_in_str, Station_pos, longitud)
Title_pos = Title_pos + 7
Longitud = 0
Hacer
Longitud de incr
Puntero = Title_pos + longitud
Temp_str = Mid (uart_in_str, puntero, 1)
Bucle hasta Temp_str = Chr (13) o Temp_str = ""
Si longitud > 60 entonces longitud = 60
Título = Mid (uart_in_str, Title_pos, longitud)
Si Station_pos = 6 entonces estacionario = "Nombre no encontrado!"
Si Title_pos = 7 entonces Title = "Título no encontrado!"
Volver
Empty_buffer:
Hacer
Uart_in = Inkey()
Uart_buffer = Ischarwaiting()
Bucle hasta Uart_buffer = 0
Volver
Readclock:
I2cstart
I2cwbyte Ds1307w
Administradores de I2cwbyte
I2cstop
I2cstart
I2cwbyte Ds1307r
I2crbyte minutos, Ack
I2crbyte horas, Nack
Horas = horas y B00111111 ' elimina el bit6 y bit7
Horas = Makedec(hours) ' convierte de BCD a Decimal
Minutos = Makedec(mins)
Tube(2) = minutos / 10 ' divide las horas y minutos en
Temp = Tube(2) * 10 4 dígitos para que puede ser aparezca
Tube(1) = minutos - temperatura
Tube(4) = horas / 10
Temp = Tube(4) * 10
Tube(3) = horas - Temp
Temp = Tube(4)
X = 48
GoSub Clockpic
Temp = Tube(3)
X = 72
GoSub Clockpic
Temp = 11
X = 96
GoSub Clockpic
Temp = Tube(2)
X = 120
GoSub Clockpic
Temp = Tube(1)
X = 144
GoSub Clockpic
Volver
Setclock:
Minutos = Makebcd(mins)
Horas = Makebcd(hours)
Restablecer Hours.6
I2cstart
I2cwbyte Ds1307w
I2cwbyte Adsecs
I2cwbyte & B00000000
I2cwbyte minutos
I2cwbyte horas
I2cstop
Horas = horas y B00111111 ' elimina el bit6 y bit7
Horas = Makedec(hours) ' convierte de BCD a Decimal
Minutos = Makedec(mins)
Volver
Clockpic:
Si Temp = 1 Showpic X, 0, 1
Si Temp = 2 Showpic X, 0, 2
Si Temp = 3 Showpic X, 0, 3
Si Temp = 4 Showpic X, 0, 4
Si Temp = 5 Showpic X, 0, 5
Si Temp = 6 Showpic X, 0, 6
Si Temp = 7 Showpic X, 0, 7
Si Temp = 8 Showpic X, 0, 8
Si Temp = 9 Showpic X, 0, 9
Si Temp = 0 Showpic X, 0, 0
Si Temp = 11 Showpic X, 0, Dp
Volver
Intro:
$bgf "wifiradio.bgf"
Jugar:
$bgf "play.bgf"
Pausa:
$bgf "pause.bgf"
Stopp:
$bgf "stop.bgf"
Volumen:
$bgf "volume.bgf"
Sintonizador:
$bgf "tuner.bgf"
Reloj:
$bgf "clock.bgf"
0:
$bgf "0.bgf"
1:
$bgf "1.bgf"
2:
$bgf "2.bgf"
3:
$bgf "3.bgf"
4:
$bgf "4.bgf"
5:
$bgf "5.bgf"
6:
$bgf "6.bgf"
7:
$bgf "7.bgf"
8:
$bgf "8.bgf"
9:
$bgf "9.bgf"
DP:
$bgf "dp.bgf"
Streep:
$bgf "streep.bgf"
Tunerlist:
Datos "", "red de 1920", "KCEA", "FM Tango Junin Argentina", "TANGOCLUB"
Tunerlist2:
Datos "http://64.5.130.43:80", "http://198.182.76.2:8000", "http://200.58.116.222:10580", http://190.245.64.194:8000