Post on 05-Apr-2018
7/31/2019 Programaci n Del Picaxe
1/13
Programacin del PICAXE
Ejemplos de aplicacin
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
7/31/2019 Programaci n Del Picaxe
2/13
main:
high 0
wait 1
low 0
wait 1
goto main
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
7/31/2019 Programaci n Del Picaxe
3/13
Ejemplo 1: flashear un LED
Este programa flashea el LED conectado al pin 1 de salida encendindoloy apagndolo 15 veces . El nmero de veces que el cdigo ha sido repetidoes almacenado en la memoria RAM de propsito general del PICAXEusando la variable b1 ( el PICAXE tiene 14 variables de propsito generalnominadas b0 a b13).
Estas variables pueden ser renombradas usando el comando symbolpara hacerlo ms fcil de recordar.
symbol contador = b1 define la variable b1 como contadorsymbol LED = 4 define el pin 4 con el nombre LED
main:for contador = 1 to 15 inicio del lazo for...next
high LED pone el pin 4 a altopause 500 espera por 0.5 segundolow LED pone el pin 7 a bajopause 500 espera por 0.5 segundo
next contador fin del del lazo for...nextend fin del programa
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
7/31/2019 Programaci n Del Picaxe
4/13
main:
sound 2,(50,100) frecuencia 50, duracin 100
sound 2,(100,100) frecuencia 100, duracin 100
sound 2,(120,100) frecuencia 120, duracin 100pause 1000 espera 1 segundo
goto main regresa al inicio
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
Ejemplo2: generando sonidos
7/31/2019 Programaci n Del Picaxe
5/13
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
7/31/2019 Programaci n Del Picaxe
6/13
playSyntax:
PLAY tune,LED- Tune is a variable/constant (0 - 3) which specifies which tune to play
0 - Happy Birthday1 - Jingle Bells2 - Silent Night3 - Rudolf the Red Nosed Reindeer
- LED is a variable/constant (0 -3) which specifies if other outputs flash at the same time as the tune isbeing played.
0 - No outputs1 - Output 0 flashes on and off2 - Output 4 flashes on and off3 - Output 0 and 4 flash alternately
Function:Play an internal tune on the PICAXE-08M (i/o pin2).
Description:The PICAXE-08M can play musical tones. The PICAXE-08M is supplied with 4 pre-programmed
internal tunes, which can be output via the play command. As these tunes are included within thePICAXE-08M bootstrap code, they use very little program memory. To generate your own tunesuse the tune command, although this requires a much greater amount of program memeory.
See the Tune command for suitable piezo / speaker circuits.Affect of increased clock speed:
The tempo (speed) of the tune is doubled at 8MHz!Example:
play 3,1 rudolf red nosed reindeer with output 0 flashingpoke
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
7/31/2019 Programaci n Del Picaxe
7/13
Una Resistencia Dependiente de Luz (LDR) es una resistencia que cambia su valor deacuerdo a la luz que incide en ella.
A commonly used device, the ORP-12, has a high resistance in the dark, and a lowresistance in the light.
Connecting the LDR to the microcontroller is very straight forward, but some software
calibrating is required.
It should be remembered that the LDR response is not linear, and so the readings willnot change in exactly the same way as with a potentiometer.
In general there is a larger resistance change at brighter light levels. This can becompensated for in the software by using a smaller range at darker light levels.
Experiment to find the most appropriate settings for the circuit.
Its resistance changes with light level. In bright light its resistance is low (typicallyaround 1k). In darkness its resistance is high (typically around 1M)
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
7/31/2019 Programaci n Del Picaxe
8/13
main: readadc 0,b1 lee el valorif b1
7/31/2019 Programaci n Del Picaxe
9/13
El PICAXE-08
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
7/31/2019 Programaci n Del Picaxe
10/13
El PICAXE-08Microcontroladores
EL PICAXE
Carlos E. Canto Quintal M.C.
Procesador Real PIC 12F629-I/P
Memoria de Programa 128 bytes
Lmite del tamao del
cdigo fuente 40 lneas promedio
Salidas digitales 4 lneas, una fija, 3 de acceso programable individualmente o todas las
lneas. Capacidad de manejo directo de LEDs/ piezoelctrico
Entradas Digitales 4 lneas, una fija, 3 de acceso programable individual o todas las lneas
Entradas Analgicas 1 lnea que corresponde a una lnea de las entradas digitales
Resolucin Anloga 4 bits el 30% del voltaje alto de entrada no se usa
Salida Anloga No ver salida PWM
Salida PWM Cualquiera de las 4 salidas digitales . Slamnente mientras se ejecuta el
comando PWM
Entrada Serial Cualquiera de las 4 entradas digitales Mximo 2400 bps
Salida Serial Cualquiera de las 4 salidas digitales. Mximo 2400 bps
Oscilador Interno 4MHz RC
7/31/2019 Programaci n Del Picaxe
11/13
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
SALIDA DIGITALHIGH pone un pin de salida alto (on) . High 2 pone en on el pin2LOW pone un pin de salida en bajo (off). Low 2 pone el pin 2 offTOGGLE conmuta el estado de un pin de salida.OUTPUT hace a un pin salida. Output 1 hace al pin1 una salidaINPUT hace a un pin entrada. Input 1 hace el pin1 un pin de entradaREVERSE Invierte el estado de entrada/salida de un pin.
PULSOUT Emite un pulso en un pin por un dado tiempo.ENTRADA DIGITAL
IF THEN Brinca a una lnea nueva de programa dependiendo de una condicinde entrada. If b1 < b2 then motoroff
PULSIN Mide la duracin en on de un pulso.
SALIDA ANLOGA
SOUND Emite un sonido. 0 = sin sonido, 255 = hiss. Sound 2, (100, 20) suena en elpin 2 un tono de 5Khz, por 0.2 s
Valores de las Notas : A(49), As(51), B(54), C(57), Cs(61), D(65), Ds(71), E(78),F(88), Fs(101), G(119)
PWM proporciona a una salida una seal de Modulacin de Ancho de Pulso (PWM).PWM 1, 50, 10 pulsa el pin 1, con un ciclo de trabajo 50/255, 10 ciclos
7/31/2019 Programaci n Del Picaxe
12/13
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
ENTRADA ANLOGA
READADC Lee el canal anlogo a una variable. Read 1, b0 lee el pin 1 anlogo a b0
FLUJO DE PROGRAMAFOR.. NEXT Establish a FOR-NEXT loop. For b1=0 to 100 step 10 Counts in tens
BRANCH Jump to address specified by offset
GOTO Jump to address. If b1=5 goto motoroff
GOSUB Jump to subroutine at address.
RETURN Return from subroutine
IF.. THEN Compare and conditionally jump
MANIPULACIN DE VARIABLES{LET} Perform variable mathematics.
LOOKUP Lookup data specified by offset and store in variable.
LOOKDOWN Find targets match number (0-N) and store in variable
RANDOM Generate a pseudo-random number
SERIAL I/OSEROUT Output serial data from output pin. Serout 0, n2400, (65) pin 0, 2400 bps, send
ASCII 65
SERIN Serial input data on input pin. Serin 0, n2400, ("A") pin 0, 2400 bps, waits forASCII 65
7/31/2019 Programaci n Del Picaxe
13/13
MicrocontroladoresEL PICAXE
Carlos E. Canto Quintal M.C.
ACCESO A EEPROM INTERNAEEPROM Store data in data EEPROM before downloading BASIC program
READ Read data EEPROM location into variable
WRITE Write variable into data EEPROM location. Write 220, b1 store byte b1 intoaddress 220
BAJA DE POTENCIANAP Enter low power mode for short period (up to 2.3 sec)
SLEEP Enter low power mode for period (up to 65535 sec)
END Power down until reset, an indefinate sleep
MISCELNEAPAUSE Wait for up to 65535 milliseconds
WAIT Wait for up to 65 secondsDEBUG Outputs variable to PC via programming lead. Debug b0 shows b0 value on
screen