![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
pplu1963
Joined: 06 Apr 2005 Posts: 1
|
dimmer 12f675 help!!! |
Posted: Wed Apr 06, 2005 9:24 am |
|
|
Could anyone explain me why this code does not run properly?
Lot of thanks.
// PROYECTO DIMMER DIGITAL ////////////////////////////////
#include <12F675.h>
#device ADC=10
#fuses INTRC_IO,WDT,PUT,NOPROTECT,NOCPD,NOMCLR,BROWNOUT
#use delay(clock=4000000,restart_wdt)
#ROM 0x3ff = {0x3478} // Valor para cada componente
#define GP0 PIN_A0 // No usado
#define GP1 PIN_A1 // Triac
#define GP2 PIN_A2 // Zero Cross
#define GP3 PIN_A3 // Control de Inicio
#define GP4 PIN_A4 // Led
#define GP5 PIN_A5 // No usado
#ZERO_RAM
set_tris_a( 0b000010001 );
int j=1; int valor=80; long i=0; long k=0; int l=0;
void init()
{
disable_interrupts(GLOBAL);
disable_interrupts(INT_EXT);
disable_interrupts(INT_TIMER0);
output_low(GP1); // Desconecta el triac
setup_comparator(NC_NC_NC_NC); // No comparadores
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
delay_ms(1000);
}
/// Interrupción del TIMER0, provoca el retardo deseado antes de la excitación
#INT_TIMER0
void tempo()
{
output_high(GP1); // Ha transcurrido el tiempo, activo la salida
}
// Interrupción Externa, provocada por el paso por 0V de la señal de entrada
#INT_EXT
void externa()
{
set_timer0(valor);
output_low(GP1);
enable_interrupts(INT_TIMER0);
if (j==0)
{
output_high(GP4);
j=1;
ext_int_edge(H_TO_L); // Cambio la detección del flanco, para que la
} // proxima sea de bajada
else if(j==1)
{
output_low(GP4);
j=0;
ext_int_edge(L_TO_H); // La próxima interrupción será de subida
}
}
void main()
{
init();
enable_interrupts(INT_EXT);
ext_int_edge(L_TO_H);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_64);
enable_interrupts(GLOBAL);
do{
if (input (GP3))
{
for(i=0;i<999;i++)
{
delay_ms(1);
k++;
If(k>999)
{
k=0;
valor++;
}
if (valor >= 252) valor=252;
if(!input(GP3)) break;
}
}
else
{
disable_interrupts(INT_TIMER0);
valor=80;
output_low(GP1);
output_low(GP4);
i=0;
k=0;
}
}while(true);
} |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Apr 06, 2005 9:45 am |
|
|
There are several problems, and I haven't looked very far...
The 'set_tris_A' command, is not a definition, it needs to actually be called (inside main, or a subroutine). However it has no real effect, unless you specify #use fast_io(a) (which is a definition, and does not have to be executed).
If the processor executes the line:
if(!input(GP3)) break;
It will break out of the enclosing do..while, drop off the end of the program, and sleep.
You should clear the external interrupt interrupt flag, before enabling this interrupt. Otherwise the act of selecting the 'edge' to use, may result in a spurious interrupt being executed, by setting the flag.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|