CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

dimmer 12f675 help!!!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pplu1963



Joined: 06 Apr 2005
Posts: 1

View user's profile Send private message

dimmer 12f675 help!!!
PostPosted: Wed Apr 06, 2005 9:24 am     Reply with quote

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);

}
Ttelmah
Guest







PostPosted: Wed Apr 06, 2005 9:45 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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