Escolar Documentos
Profissional Documentos
Cultura Documentos
UMG
Simulaciones
PICAXE BASIC:
•Conversión Análogo a Digital
• i2c I/O
• Infrarrojo I/O
• PC keyboard input
• Pulse-width modulation (PWM) for DC motor control
• Servo motor control
• Serial I/O
•Sound and music output
• Serial Peripheral Interface (SPI) I/O
• Medición de Temperatura
SISTEMA DE PROGRAMACIÓN DE MICROCONTROLADOR
Etiquetas
Las direcciones de programa son asignadas siguiendo el
símbolo con dos puntos (:).
CONSTANTES
Las llamadas constantes pueden ser creadas de manera similar
a las variables. Puede ser más conveniente usar un nombre de
constante en lugar de un número constante. Si el número
necesita ser cambiado, únicamente puede ser cambiado en un
lugar del programa donde se define la constante. No pueden
guardarse datos variables dentro de una constante.
Bits: PIN0, PIN1, PIN2, PIN3, PIN4, PIN5, PIN6, PIN7 (conjuntamente
igual PINS)
BIT0, BIT1, BIT2, BIT3, BIT4, BIT4, BIT5, BIT6, BIT7 (conjuntamente
igual B0)
BIT8, BIT9, BIT10, BIT11, BIT12, BIT13, BIT14, BIT15 (conjuntamente
igual B1)
if pinC.2 = 1 then
goto encender
else
goto apagar
goto inicio
endif
encender:
high b.3
goto inicio
apagar:
low B.3
goto inicio
‘EJEMPLO
start:
for b4 = 1 to 10
pause 100
if pinC.2 = 1 then alarm
next b4
low B.3
high B.1
pause 500
low B.1
goto start
alarm:
high B.3
goto start
Analogue Inputs
Analogue inputs can be connected in a potential divider arrangement
between V+ and 0V. The analogue reference is the supply voltage,
and the analogue signal must not exceed the supply voltage.
main:
readadc 0,b1 ; lee el valor del pin0 en la variable b1
if b1<75 then light1 ; si b1 es menor a 75 then light 1
if b1<175 then light2 ; si b1 es menor a 175 then light 2
goto light3 ; si b1 es mayor a 175 then light 3
light1:
high 1
low 2
low 3
goto main
light2:
low 1
high 2
low 3
goto main
light3:
low 1
low 2
high 3
goto main
main:
low b.1
low b.2
low b.3
low b.4
readadc 0,b1
if b1<50 then light1
if b1<100 then light2
if b1<145 then light3
if b1<175 then light4
goto main
light1:
high b.1
pause 2000
goto main
light2:
high b.2
pause 2000
goto main
light3:
high b.3
pause 2000
goto main
light4:
high b.4
pause 2000
goto main
Cambiar este transistor por un NPN 2N3904
do
high C.1
pause 1000
low C.1
pause 1000
loop
do
high C.1
pause 1000
low C.1
pause 1000
high C.2
pause 1000
Low C.2
pause 1000
loop
main:
readtemp C.1,b0 ; lee temperatura en variable b0
sertxd ("La temperatura",#b0,cr,lf)
pause 1000
goto main
main:
readtemp C.1,b0 ; lee temperatura en variable b0
sertxd ("La temperatura",#b0,cr,lf)
pause 1000
if b0>60 then
goto ventilador
else
goto apagar
end if
goto main
ventilador:
do
high b.1
readtemp C.1,b0
loop until b0<40
apagar:
low b.1
goto main
;TRANSMISOR
main:
;setfreq m4
if pinc.1 = 1 and b0 = 0 then encender
if pinc.1 = 1 and b0 = 1 then apagar
goto main
encender:
high c.2
b0 = 1
serout c.4, n2400, ("aaaaaaaaaaaaaaaa") ;SINCRONIZA MODULOS RF
pause 50
serout c.4, n2400, ("led", b0)
goto main
apagar:
low c.2
b0 = 0
serout c.4, n2400, ("aaaaaaaaaaaaaaaa") ;SINCRONIZA MODULOS RF
pause 50
serout c.4, n2400, ("led", b0)
goto main
;RECEPTOR
main:
;setfreq m4
serin c.3, n2400, ("led"), b0
sertxd ("valor: ",#b0,13,10) ;ver en pantalla B0
if b0 = 1 then
gosub encender
else b0 = 0
gosub apagar
endif
encender:
high c.2
goto main
apagar:
low c.2
goto main
Salida con bocina
tune B.1, 5,
($00,$04,$06,$49,$07,$04,$00,$69,$66,$66,$66,$E7,$6C,$
66,$66,$66,$67,$2A,$2B)
pause 3000
goto main