#include "12c508a.h"
#use delay(clock=4000000)
#use fast_io(b)
#fuses INTRC,NOWDT,NOPROTECT,NOMCLR
int iEntrada=0;
void main()
{
SET_TRIS_B(0b001000);
//Comprobar el pulsador.
if(input(PIN_B4) == FALSE)
{
// Esperar a se deje de pulsar.
while (input(PIN_B4) == FALSE)
{
}
// Esperar un tiempo para evitar rebotes.
delay_ms(150);
// Cambiar frecuencia salida
iEntrada ++;
if(iEntrada >=4) iEntrada = 0;
//Indicar en los LEDs la frecuencia seleccionada.
switch(iEntrada){
case 0x0:
output_low(PIN_B5);
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
break;
case 0x1:
output_low(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B5);
break;
case 0x2:
output_low(PIN_B1);
output_high(PIN_B0);
output_high(PIN_B2);
output_high(PIN_B5);
break;
case 0x3:
output_low(PIN_B2);
output_high(PIN_B1);
output_high(PIN_B0);
output_high(PIN_B5);
break;
}
}
//Salida de frecuencia
switch(iEntrada)
{
case 0:
output_high(PIN_B4); delay_ms(100);
output_low(PIN_B4); delay_ms(100);
break;
case 1:
output_high(PIN_B4); delay_ms(200);
output_low(PIN_B4); delay_ms(200);
break;
case 2:
output_high(PIN_B4); delay_ms(400);
output_low(PIN_B4); delay_ms(400);
break;
case 3:
output_high(PIN_B4); delay_ms(800);
output_low(PIN_B4); delay_ms(800);
break;
}
}
if(input(PIN_B4) == FALSE)
{
// Esperar a se deje de pulsar.
while (input(PIN_B4) == FALSE)
{
}
Dices que tienes conectado un pulsador a GP3, pero usas GP4 para hacer el testeo :lol:setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);-Esta linia que hace? Porque ademas despues no usas el TMR0 no?
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);#use fast_io (b)en resumen, le dice al compilador que la configuración de los puertos la vas a realizar tú mediante set_tris_b(xxx).set_tris_b(xxx), y no cada vez que se lee o se escribe en el puerto, logrando así que el acceso a los puertos sea más rápido, de ahí el fast_io.//////// Standard Header file for the PIC12C508A device ////////////////
#device PIC12C508A
#nolist
//////// Program memory: 512x12 Data RAM: 25 Stack: 2
//////// I/O: 6 Analog Pins: 0
//////// C Scratch area: 07 ID Location: 0200
//////// Oscilator Calibration Address: 05
//////// Fuses: LP,XT,INTRC,RC,NOWDT,WDT,PROTECT,NOPROTECT,NOMCLR,MCLR
////////
////////////////////////////////////////////////////////////////// I/O
// Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(),
// PORT_x_PULLUPS(), INPUT(),
// OUTPUT_LOW(), OUTPUT_HIGH(),
// OUTPUT_FLOAT(), OUTPUT_BIT()
// Constants used to identify pins in the above are:
#define PIN_B0 48
#define PIN_B1 49
#define PIN_B2 50
#define PIN_B3 51
#define PIN_B4 52
#define PIN_B5 53
////////////////////////////////////////////////////////////////// Useful defines
#define FALSE 0
#define TRUE 1
#define BYTE int8
#define BOOLEAN int1
#define getc getch
#define fgetc getch
#define getchar getch
#define putc putchar
#define fputc putchar
#define fgets gets
#define fputs puts
////////////////////////////////////////////////////////////////// Control
// Control Functions: RESET_CPU(), SLEEP(), RESTART_CAUSE()
// Constants returned from RESTART_CAUSE() are:
#define WDT_FROM_SLEEP 3
#define WDT_TIMEOUT 11
#define MCLR_FROM_SLEEP 19
#define MCLR_FROM_RUN 27
#define NORMAL_POWER_UP 25
#define BROWNOUT_RESTART 26
////////////////////////////////////////////////////////////////// Timer 0
// Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER_0(),
// SET_TIMER0() or SET_RTCC(),
// GET_TIMER0() or GET_RTCC()
// Constants used for SETUP_TIMER_0() are:
#define T0_INTERNAL 0
#define T0_EXT_L_TO_H 32
#define T0_EXT_H_TO_L 48
#define T0_DIV_1 8
#define T0_DIV_2 0
#define T0_DIV_4 1
#define T0_DIV_8 2
#define T0_DIV_16 3
#define T0_DIV_32 4
#define T0_DIV_64 5
#define T0_DIV_128 6
#define T0_DIV_256 7
#define T0_8_BIT 0
#define RTCC_INTERNAL 0 // The following are provided for compatibility
#define RTCC_EXT_L_TO_H 32 // with older compiler versions
#define RTCC_EXT_H_TO_L 48
#define RTCC_DIV_1 8
#define RTCC_DIV_2 0
#define RTCC_DIV_4 1
#define RTCC_DIV_8 2
#define RTCC_DIV_16 3
#define RTCC_DIV_32 4
#define RTCC_DIV_64 5
#define RTCC_DIV_128 6
#define RTCC_DIV_256 7
#define RTCC_8_BIT 0
// Constants used for SETUP_COUNTERS() are the above
// constants for the 1st param and the following for
// the 2nd param:
////////////////////////////////////////////////////////////////// WDT
// Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS() (see above)
// RESTART_WDT()
// WDT base is 18ms
//
#define WDT_18MS 8
#define WDT_36MS 9
#define WDT_72MS 10
#define WDT_144MS 11
#define WDT_288MS 12
#define WDT_576MS 13
#define WDT_1152MS 14
#define WDT_2304MS 15
#define DISABLE_PULLUPS 0x40 // for 508 and 509 only
#define DISABLE_WAKEUP_ON_CHANGE 0x80 // for 508 and 509 only
#ifndef PIN_CHANGE_FROM_SLEEP
#define PIN_CHANGE_FROM_SLEEP 0x90 // for 508 and 509 only
#endif
#list
pablomanieri y MGLSOFT, muchas gracias a los dos!
Menudo par de despistes que he tenido, con lo del ciclo infinito y con no poner el pin que uso...
MGLSOFT, pero hay algo que no tengo claro, son dos cosas:Citarsetup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);-Esta linia que hace? Porque ademas despues no usas el TMR0 no?
-La directiba #use fast_io(b) realmente que hace? lo que encuentro por ahi no esta muy bien explicado...
Por cierto, no se que hago mal pero no puedo habrir el esquematico.
#include<12f508.c>
Segun tengo entendido la libreria es la misma, no? microchip dice que se considere el mismo PIC y
el mplab no tiene la libreria del 12F508...
while (input(PIN_B3) == FALSE)while (!input(PIN_B3) )if(input(PIN_B3) == FALSE)if(!input(PIN_B3) )
#include <12F508.h>
#use delay(clock=4000000)
#fuses INTRC,NOWDT,NOPROTECT,NOMCLR
#use fast_io(B)
int iEntrada = 0;
void main()
{
//setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
set_tris_b(0b001000);
output_b(0);
while(1){
if(!input(PIN_B3) )
{
// Esperar a que lse deje de pulsar el pulsador.
while (!input(PIN_B3) ) { }
// Esperar un temps de precaucion per a evitar rebotes
delay_ms(150);
// Cambiar frecuencia
iEntrada ++;
if(iEntrada >3){
iEntrada = 0;
}
//Indicar en els LEDs la frecuencia seleccionada
switch(iEntrada){
case 0x0:
output_low(PIN_B5);
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
break;
case 0x1:
output_low(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B5);
break;
case 0x2:
output_low(PIN_B1);
output_high(PIN_B0);
output_high(PIN_B2);
output_high(PIN_B5);
break;
case 0x3:
output_low(PIN_B2);
output_high(PIN_B1);
output_high(PIN_B0);
output_high(PIN_B5);
break;
}
}
//Salidas de frecuencias
switch(iEntrada)
{
case 0:
output_high(PIN_B4); delay_ms(1000);
output_low(PIN_B4); delay_ms(1000);
break;
case 1:
output_high(PIN_B4); delay_ms(4000);
output_low(PIN_B4); delay_ms(4000);
break;
case 2:
output_high(PIN_B4); delay_ms(6000);
output_low(PIN_B4); delay_ms(6000);
break;
case 3:
output_high(PIN_B4); delay_ms(90000);
output_low(PIN_B4); delay_ms(90000);
break;
}
} //while
}switch(iEntrada)
{
case 0:
output_high(PIN_B4); delay_ms(1000);
output_low(PIN_B4); delay_ms(1000);
break;
case 1:
output_high(PIN_B4); delay_ms(4000);
output_low(PIN_B4); delay_ms(4000);
break;
case 2:
output_high(PIN_B4); delay_ms(6000);
output_low(PIN_B4); delay_ms(6000);
break;
case 3:
output_high(PIN_B4); delay_ms(90000);
output_low(PIN_B4); delay_ms(90000);
break;
}Syntax:
delay_ms (time)
Parameters:
time - a variable 0-65535(int16) or a constant 0-65535