#include <16F628A.h>
#fuses INTRC_IO, NOWDT, NOMCLR,NOPROTECT, BROWNOUT, NOPUT, NOLVP
#use delay(clock = 4MHz)
#use fast_io(B)
#reserve 0x20:0x25 //reservo esas posiciones para los contadores del retardo
void parpadeo();
void main()
{
set_tris_A(0x00);
set_tris_B(0x00);
while(TRUE)
{
parpadeo();
}
}
void parpadeo()
{
int8 PDel0;
int8 PDel1;
#locate PDel0=0x20 ;guardo las variables en las posiciones reservadas
#locate PDel1=0x21
#asm
clrf 0x03 ;me voy al banco 0
bcf 0x06,5 ;apago
call DEMORA ;retardo
bsf 0x06,5 ;prendo
call DEMORA ;retardo
DEMORA movlw .239 ; 1 set numero de repeticion (B)
movwf PDel0 ; 1 |
PLoop1 movlw .232 ; 1 set numero de repeticion (A)
movwf PDel1 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2 goto PDelL3 ; 2 ciclos delay
PDelL3 clrwdt ; 1 ciclo delay
decfsz PDel1,1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0,1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
PDelL4 goto PDelL5 ; 2 ciclos delay
PDelL5 goto PDelL6 ; 2 ciclos delay
PDelL6 goto PDelL7 ; 2 ciclos delay
PDelL7 clrwdt ; 1 ciclo delay
return ; 2+2 Fin.
#endasm
}Yo tampoco me acuerdo demasiado de asm, pero siempre que iba a utilizar un call tenía la precaución de tener definido de antemano el sitio al cual quería ir. Te pongo un ejemplo para que se entienda mejorCódigo: ASM
; supongamos que aquí comienza el codigo en asm goto comienzo etiqueta bcf PORTB,0 return comienzo call etiqueta ....... ........ ........
Y es muy necesario el uso del asm? Quiza con C se pueda realizar sin perder mucha exactitud. No podria aconsejarte algo pues, al no saber asm, no se que es lo que intentas hacer.
Básicamente es al igual que en C, salvo que el C te permite definir la función (sin que sea necesaria su implementación) antes del main.
O sea que en asm, tiene que figurar la implementación de una función antes de que se la pueda llamar mediante un call.
falflores según te leo, dices que requieres precisión en los retardos, pero
¿y sabes los tiempos que se gasta C al momento de entrar y salir de la función parpadeo?
porque podrías intentar hacer los retardos por interrupciones al timer (en C), y mediante simulación, calculas los tiempos (teóricamente ) asignando puntos de rupturas en las lineas de código a retener.
// (C) copyright 2003 j.d.sandoz / jds-pic !at! losdos.dyndns.org
// released under the GNU GENERAL PUBLIC LICENSE (GPL)
// refer to http://www.gnu.org/licenses/gpl.txt
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/***********************1Wire Class***********************/
/*Description: This class handles all communication */
/* between the processor and the 1wire */
/* sensors.
/*********************************************************/
/*-------1-wire definitions-------*/
#define ONE_WIRE_PIN PIN_B5
/*******************1-wire communication functions********************/
/************onewire_reset*************************************************/
/*This function initiates the 1wire bus */
/* */
/*PARAMETERS: */
/*RETURNS: */
/*********************************************************************/
void onewire_reset() // OK if just using a single permanently connected device
{
output_low(ONE_WIRE_PIN);
delay_us(500); // pull 1-wire low for reset pulse
output_float(ONE_WIRE_PIN); // float 1-wire high
delay_us(500); // wait-out remaining initialisation window.
output_float(ONE_WIRE_PIN);
}
/*********************** onewire_write() ********************************/
/*This function writes a byte to the sensor.*/
/* */
/*Parameters: byte - the byte to be written to the 1-wire */
/*Returns: */
/*********************************************************************/
void onewire_write_byte(int data)
{
int count;
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us(2); // pull 1-wire low to initiate write time-slot.
output_bit(ONE_WIRE_PIN, shift_right(&data,1,0)); // set output bit on 1-wire
delay_us(60); // wait until end of write slot.
output_float(ONE_WIRE_PIN); // set 1-wire high again,
delay_us(2); // for more than 1us minimum.
}
}
/*********************** read1wire() *********************************/
/*This function reads the 8 -bit data via the 1-wire sensor. */
/* */
/*Parameters: */
/*Returns: 8-bit (1-byte) data from sensor */
/*********************************************************************/
int onewire_read_byte()
{
int count,data;
for (count=0;count<8;++count)
{
output_low(ONE_WIRE_PIN);
delay_us(2); // pull 1-wire low to initiate read time-slot.
output_float(ONE_WIRE_PIN); // now let 1-wire float high,
delay_us(8); // let device state stabilise,
shift_right(&data,1,input(ONE_WIRE_PIN)); // and load result.
delay_us(120); // wait until end of read slot.
}
return(data);
} float ds1820_read()
{
int8 busy=0,temp1,temp2;
signed int16 temp3;
float result;
onewire_reset();
onewire_write_byte(0xCC);
onewire_write_byte(0x44);
while (busy == 0) busy = onewire_read_byte();
onewire_reset();
onewire_write_byte(0xCC);
onewire_write_byte(0xBE);
temp1=onewire_read_byte();
temp2=onewire_read_byte();
temp3=make16(temp2, temp1);
//result=(float)temp3/2.0); //Calculation for DS18S20 with 0.5 deg C resolution
result=(float)temp3/16.0; //Calculation for DS18B20 with 0.1 deg C resolution
delay_ms(200);
return(result);
} Si eres el creador del hilo, tu mismo puedes cambiar el nombre del hilo...
:mrgreen: :mrgreen:
Si eres el creador del hilo, tu mismo puedes cambiar el nombre del hilo...
:mrgreen: :mrgreen:
Perdón, pero busque como y la verdad no hallo la forma, alguien me dodría decir como se le cambia el título a un post?
Si eres el creador del hilo, tu mismo puedes cambiar el nombre del hilo...
:mrgreen: :mrgreen:
Perdón, pero busque como y la verdad no hallo la forma, alguien me dodría decir como se le cambia el título a un post?
Pulsas Modificar, luego en Asunto cambias el titulo y luego Guardar :mrgreen: