Documentos de Académico
Documentos de Profesional
Documentos de Cultura
***********************
#fuses HS,NOWDT,PUT,NODEBUG,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
int16 tiempo,distancia=0,valor_leido=0;
#USE standard_io(b)
void main(){
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
output_low(pin_c0);
set_tris_d(0b00000000);
set_tris_c(0b00000000);
output_low(pin_e1);
while(true){
led_state=!led_state;
output_high(trig);
delay_us(20);
output_low(trig);
while(!input(echo))
{}
set_timer1(0);
while(input(echo))
{}
tiempo=get_timer1();
distancia=(tiempo*10)/(59.0);
if(distancia<=10){
valor_leido=0;
output_d(valor_leido);
else if(distancia>=100){
valor_leido=169;
output_d(valor_leido);
else{
valor_leido=((169/95.0)*((distancia)-10));
output_d(valor_leido);
}
************************************************COMPENSADOR****************
*******************
#device adc=10
#fuses HS,NOWDT,PUT,NODEBUG,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
int8 f=0;
#bit p1 =f.0
#bit p2 =f.1
#bit p3 =f.2
int16 Dat=0;
int16 cnt_led=0;
float value=0;
float vi[22]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float vo[4]={0,0,0,0};
float xn=0,rn=0;
#int_TIMER1
void TIMER1_isr(void){
//T=(4*8*(65536-42411))/(20M)=0.037
set_TIMER1(42411);
delay_us(20); //a small delay is required after setting the channel and before
read
value=read_adc(); //starts the conversion and reads the result and store it in value
rn=value/1023.0;
set_TIMER1(42411);
delay_us(20); //a small delay is required after setting the channel and before
read
value=read_adc(); //starts the conversion and reads the result and store it in value
xn=value/1023.0; //starts the conversion and reads the result and store it in value
vi[0]= rn - xn;
//vo[2] = 0.001127*vi[0]+0.002254*vi[1]+0.001127*vi[2]+1.923*vo[1]-0.9295*vo[0];
vo[1] = 0.0246*vi[1]+0.0246*vi[0]+vo[0];
if(vo[1]<0){vo[1]=0;}
else if(vo[1]>1){vo[1]=1;}
Dat=vo[1]*1023;
output_d(make8(Dat,0));
output_c(make8(Dat,1));
vi[2]=vi[1];
vi[1]=vi[0];
vo[0]=vo[1];
vo[1]=vo[2];
vo[2]=vo[3];
#int_TIMER0
void TIMER0_isr(void)
cnt_led++;
if(cnt_led==100){
led_state=!led_state;
cnt_led=0;}
set_TIMER0(120);
void main(){
set_tris_d(0b00000000);
set_tris_c(0b00000000);
PORT_B_PULLUPS(true);
enable_interrupts(INT_RB);
output_float(pin_b4);
output_float(pin_b5);
output_low(pin_a5);
output_low(pin_e0);
output_low(pin_e1);
//output_low(pin_e2);
enable_interrupts(global); // ENABLE_INTERRUPTS(GLOBAL)
do
while(TRUE);
************************************************PWM*************************
******************
const int adc1 = A3; // select the input pin for the potentiometer
const int pwm1 = 14; // select the pin for the LED
const int ledPin1 = 12; // select the pin for the LED
int sal1 = 0; // variable to store the value coming from the sensor
int sal2 = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(adc1,INPUT);
// declare the ledPin as an OUTPUT:
pinMode(pwm1, OUTPUT);
pinMode(ledPin1, OUTPUT);
analogWrite(pwm1, 22);
delay(500);
analogWrite(pwm1, 23);
delay(500);
analogWrite(pwm1, 24);
delay(500);
analogWrite(pwm1, 35);
delay(500);
analogWrite(pwm1, 26);
delay(500);
analogWrite(pwm1, 34);
delay(1000);
analogWrite(pwm1, 38);
delay(500);
analogWrite(pwm1, 39);
delay(500);
analogWrite(pwm1, 40);
delay(500);
void loop()
// leemos el adc 1
datoAdc1 = analogRead(adc1);
// los sacmos como salidas cada uno de los pwm por los pines escogidos al principio
analogWrite(pwm1, sal1);
digitalWrite(ledPin1, HIGH);
delay(50);
digitalWrite(ledPin1, LOW);
delay(50);