#include <10F200.h>
#FUSES NOWDT,NOMCLR,PROTECT
#use delay(clock=4000000)
#use fast_io(b)
//GPIO
#byte GP = 0x06
//#bit X = GP.0
#bit BTN = GP.1
#bit SERVO = GP.2
//#bit X = GP.3
//Constantes
#define Pos1_High 800
#define Pos1_Low 19200
#define Pos2_High 2200
#define Pos2_Low 17800
//Variables
short flagPresionado = FALSE; //flag indica si el boton esta presionado
short Posicion = 0; //si esta en posicion 1 o 2
//Funciones
void set_options(void){
//Bit Funcion Descripcion
// 7 !GPWU Wake-up on pin change (Enable = 0, Disable = 1))
// 6 !GPPU Weak pull ups (Enable = 0, Disable = 1))
// 5 T0CS Timer0 Clock source (T0CKl pin = 1, Interno = 0)
// 4 T0SE Timer0 Source Edge (L_to_H = 0, H_to_L = 1)
// 3 PSA Prescaler assignment (WDT = 1, Timer0 = 0)
//2-0 PS Prescaler rate (mirar datasheet)
#asm
movlw 0b10000000
option
#endasm
}
void main(){
set_options(); //configura pullups, wake on change y timer
set_tris_b(0b00000010);
do{
if(BTN == 0){
if(flagPresionado == FALSE){
++Posicion;
flagPresionado = TRUE;
}
}
else
flagPresionado = FALSE;
if(Posicion == 0){ //mueve servo a posicion 1
Servo = 1;
delay_us(Pos1_High);
Servo = 0;
delay_us(Pos1_Low);
}
else{ //mueve servo a posicion 2
Servo = 1;
delay_us(Pos2_High);
Servo = 0;
delay_us(Pos2_Low);
}
}while(true);
}