Duty Serial
Duty Serial
Duty Serial
h>
#DEVICE ADC=10 //Define que el conversor trabaja a 10 bits
#include <stdlib.h>
#include <stdio.h>
#fuses INTRC_IO,NOWDT,PUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOCLKOUT
#fuses NOIESO,NOFCMEN,NOWRT,NOVCAP,NOSTVREN,NODEBUG,NOLVP
#use delay(internal,clock=8000000)
#USE RS232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7)
//Byte CONST display[10]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//Byte CONST display_a[10]= {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
#BYTE TRISA = 0X08c
#BYTE TRISB = 0X08d
#BYTE TRISC = 0X08e
#BYTE TRISD = 0X08f
#BYTE TRISE = 0X90
#BYTE PORTA = 0x0c
#BYTE PORTB = 0x0d
#BYTE PORTC = 0x0e
#BYTE PORTD = 0x0f
#BYTE PORTE = 0x10
#BYTE ANSELE = 0x190
#BYTE ANSELB = 0x18D
#BYTE ANSELA = 0x18C
#BYTE LATE = 0x110
#BYTE ADCON0 = 0x9D
#BYTE ADCON1 = 0x9E
#define an3 portc,7
#define an2 porte,2
#define an1 porte,1
#define pwm_a portc,0
#define sw3 portb,3
#define sw2 portb,2
#define sw1 portb,1
//////////////////////////////
/// definici�n de variables
//////////////////////////////
int16 volt_BIN,duty,valor1,pulso,frec;
float voltios, porc;
int32 dist, dist1;
int8 i,n;
char dato;
char valor[3];
char my_string [5];
#int_RDA
void serial_isr()
{
default:
valor=dato;
i++;
valor=0;
break;
}
}
#int_ext
void entrada() // Funcion de interrupci�n por cambio en el pin RB0
{
pulso++; // Incremeta en uno la variable pulso
}
#INT_TIMER1
void time()
{
frec=pulso*10;
set_timer1(0x9E58);//Carga del TMR1
pulso=0;
}
///////////////////////////////////
/////// PROGRAMA PRINCIPAL ////////
///////////////////////////////////
void main ()
{
////////////////////////////////
// configuracion de fusibles
////////////////////////////////
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);
//! setup_timer_2 (T2_DIV_BY_16, 255, 1); //Config.Timer2 con tabla de la
datasheet
//! setup_ccp1 (CCP_PWM); //Config. del modulo ccp en modo
PWM en Puerto C2
set_tris_a(0b11111111);
set_tris_b(0b00001111);
set_tris_c(0b10000000);
set_tris_d(0b00000000);
set_tris_e(0b00000000);
/////////////////////////
// Bucle infinito
/////////////////////////
while(TRUE)
{
{
bit_set(pwm_a);
delay_us(duty);
bit_clear(pwm_a);
delay_us(4000-duty);
}