EL PICAXE Microcontroladores Programacin del PICAXE Ejemplos de

  • Slides: 13
Download presentation
EL PICAXE Microcontroladores Programación del PICAXE Ejemplos de aplicación Carlos E. Canto Quintal M.

EL PICAXE Microcontroladores Programación del PICAXE Ejemplos de aplicación Carlos E. Canto Quintal M. C.

EL PICAXE Microcontroladores ¿ Diagrama de flujo o BASIC ? main: high 0 wait

EL PICAXE Microcontroladores ¿ Diagrama de flujo o BASIC ? main: high 0 wait 1 low 0 wait 1 goto main Carlos E. Canto Quintal M. C.

EL PICAXE Microcontroladores Ejemplo 1: flashear un LED q Este programa flashea el LED

EL PICAXE Microcontroladores Ejemplo 1: flashear un LED q Este programa flashea el LED conectado al pin 1 de salida encendiéndolo y apagándolo 15 veces. El número de veces que el código ha sido repetido es almacenado en la memoria RAM de propósito general del PICAXE usando la variable b 1 ( el PICAXE tiene 14 variables de propósito general nominadas b 0 a b 13). q Estas variables pueden ser renombradas usando el comando symbol para hacerlo más fácil de recordar. symbol contador = b 1 ‘ define la variable b 1 como “contador” symbol 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 alto pause 500 ‘ espera por 0. 5 segundo low LED ‘ pone el pin 7 a bajo pause 500 ‘ espera por 0. 5 segundo next contador ‘ fin del lazo for. . . next end ‘ fin del programa Carlos E. Canto Quintal M. C.

EL PICAXE Microcontroladores Ejemplo 2: generando sonidos main: sound 2, (50, 100) sound 2,

EL PICAXE Microcontroladores Ejemplo 2: generando sonidos main: sound 2, (50, 100) sound 2, (100, 100) sound 2, (120, 100) pause 1000 goto main ‘ frecuencia 50, duración 100 ‘ frecuencia 100, duración 100 ‘ frecuencia 120, duración 100 ‘ espera 1 segundo ‘ regresa al inicio Carlos E. Canto Quintal M. C.

Microcontroladores EL PICAXE Carlos E. Canto Quintal M. C.

Microcontroladores EL PICAXE Carlos E. Canto Quintal M. C.

Microcontroladores EL PICAXE play Syntax: PLAY tune, LED - Tune is a variable/constant (0

Microcontroladores EL PICAXE play Syntax: PLAY tune, LED - Tune is a variable/constant (0 - 3) which specifies which tune to play 0 - Happy Birthday 1 - Jingle Bells 2 - Silent Night 3 - 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 is being played. 0 - No outputs 1 - Output 0 flashes on and off 2 - Output 4 flashes on and off 3 - Output 0 and 4 flash alternately Function: Play an internal tune on the PICAXE-08 M (i/o pin 2). Description: The PICAXE-08 M can play musical tones. The PICAXE-08 M is supplied with 4 pre-programmed internal tunes, which can be output via the play command. As these tunes are included within the PICAXE-08 M bootstrap code, they use very little program memory. To generate your own tunes use 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 8 MHz! Example: play 3, 1 ‘ rudolf red nosed reindeer with output 0 flashingpoke Carlos E. Canto Quintal M. C.

EL PICAXE Microcontroladores Light Dependant Resistor (LDR) ü Una Resistencia Dependiente de Luz (LDR)

EL PICAXE Microcontroladores Light Dependant Resistor (LDR) ü Una Resistencia Dependiente de Luz (LDR) es una resistencia que cambia su valor de acuerdo a la luz que incide en ella. A commonly used device, the ORP-12, has a high resistance in the dark, and a low resistance 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 will not change in exactly the same way as with a potentiometer. In general there is a larger resistance change at brighter light levels. This can be compensated for in the software by using a smaller range at darker light levels. Experiment to find the most appropriate settings for the circuit. It’s resistance changes with light level. In bright light its resistance is low (typically around 1 k). In darkness its resistance is high (typically around 1 M) Carlos E. Canto Quintal M. C.

Microcontroladores EL PICAXE main: readadc 0, b 1 ‘ lee el valor if b

Microcontroladores EL PICAXE main: readadc 0, b 1 ‘ lee el valor if b 1<50 then light 1 ‘ rango 0 -50= 50 if b 1<100 then light 2 ‘ rango 50 -100 = 50 if b 1<145 then light 3 ‘ rango 100 -145 = 45 if b 1<175 then light 4 ‘ rango 145 -175 = 30 goto main Carlos E. Canto Quintal M. C.

EL PICAXE Microcontroladores El PICAXE-08 Carlos E. Canto Quintal M. C.

EL PICAXE Microcontroladores El PICAXE-08 Carlos E. Canto Quintal M. C.

Microcontroladores EL PICAXE El PICAXE-08 Procesador Real PIC 12 F 629 -I/P Memoria de

Microcontroladores EL PICAXE El PICAXE-08 Procesador Real PIC 12 F 629 -I/P Memoria de Programa 128 bytes Límite del tamaño del código fuente 40 líneas promedio Salidas digitales 4 líneas, una fija, 3 de acceso programable individualmente o todas líneas. Capacidad de manejo directo de LEDs/ piezoeléctrico Entradas Digitales todas líneas 4 líneas, una fija, 3 de acceso programable individual o Entradas Analógicas digitales 1 línea que corresponde a una línea de las entradas Resolución Análoga 4 bits el 30% del voltaje alto de entrada no se usa Salida Análoga No – ver salida PWM Salida PWM se ejecuta el Cualquiera de las 4 salidas digitales. Sólamnente mientras comando PWM Entrada Serial Cualquiera de las 4 entradas digitales Máximo 2400 bps Salida Serial Cualquiera de las 4 salidas digitales. Máximo 2400 bps Carlos E. Canto Quintal M. C.

EL PICAXE Microcontroladores Comandos del PICAXE-08 SALIDA DIGITAL HIGH LOW TOGGLE OUTPUT INPUT REVERSE

EL PICAXE Microcontroladores Comandos del PICAXE-08 SALIDA DIGITAL HIGH LOW TOGGLE OUTPUT INPUT REVERSE PULSOUT pone un pin de salida alto (on). High 2 pone en on el pin 2 pone un pin de salida en bajo (off). Low 2 pone el pin 2 off conmuta el estado de un pin de salida. hace a un pin salida. Output 1 hace al pin 1 una salida hace a un pin entrada. Input 1 hace el pin 1 un pin de entrada Invierte el estado de entrada/salida de un pin. Emite un pulso en un pin por un dado tiempo. ENTRADA DIGITAL IF… THEN Brinca a una línea nueva de programa dependiendo de una condición de entrada. If b 1 < b 2 then motoroff PULSIN Mide la duración en on de un pulso. SALIDA ANÁLOGA SOUND Emite un sonido. 0 = sin sonido, 255 = hiss. Sound 2, (100, 20) suena en el pin 2 un tono de 5 Khz, 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 señal de Modulación de Ancho de Pulso (PWM). PWM 1, 50, 10 pulsa el pin 1, con un ciclo de trabajo 50/255, 10 ciclos Carlos E. Canto Quintal M. C.

EL PICAXE Microcontroladores ENTRADA ANÁLOGA READADC Lee el canal análogo a una variable. Read

EL PICAXE Microcontroladores ENTRADA ANÁLOGA READADC Lee el canal análogo a una variable. Read 1, b 0 lee el pin 1 análogo a b 0 FLUJO DE PROGRAMA FOR. . NEXT BRANCH GOTO GOSUB RETURN IF. . THEN Establish a FOR-NEXT loop. For b 1=0 to 100 step 10 Counts in tens Jump to address specified by offset Jump to address. If b 1=5 goto motoroff Jump to subroutine at address. Return from subroutine Compare and conditionally jump MANIPULACIÓN DE VARIABLES {LET} LOOKUP LOOKDOWN RANDOM Perform variable mathematics. Lookup data specified by offset and store in variable. Find target’s match number (0 -N) and store in variable Generate a pseudo-random number SERIAL I/O SEROUT Output serial data from output pin. Serout 0, n 2400, (65) pin 0, 2400 bps, send ASCII 65 SERIN Serial input data on input pin. Serin 0, n 2400, ("A") pin 0, 2400 bps, waits for ASCII 65 Carlos E. Canto Quintal M. C.

EL PICAXE Microcontroladores ACCESO A EEPROM INTERNA EEPROM READ Store data in data EEPROM

EL PICAXE Microcontroladores ACCESO A EEPROM INTERNA EEPROM READ Store data in data EEPROM before downloading BASIC program Read data EEPROM location into variable WRITE Write variable into data EEPROM location. Write 220, b 1 store byte b 1 into address 220 BAJA DE POTENCIA NAP SLEEP END Enter low power mode for short period (up to 2. 3 sec) Enter low power mode for period (up to 65535 sec) Power down until reset, an indefinate sleep MISCELÁNEA PAUSE WAIT Wait for up to 65535 milliseconds Wait for up to 65 seconds DEBUG Outputs variable to PC via programming lead. Debug b 0 shows b 0 value on screen Carlos E. Canto Quintal M. C.