davoud
Full Member level 2
Hi all,
I am new in micro controller programming.
I decided to make a timer with external trigger(if external command continued we have square wave).
problem is when I change pot connected to micro I should wait one cycle to change time.
for this aim I used time interruption but there was no change to circuit working!.
help me please.
Circuit diagram
I am new in micro controller programming.
I decided to make a timer with external trigger(if external command continued we have square wave).
problem is when I change pot connected to micro I should wait one cycle to change time.
for this aim I used time interruption but there was no change to circuit working!.
Code:
#include <stdio.h>
#include <stdlib.h>
void init_ports(void)
{
TRISIO = 0b00001111; // set as output
ANSEL = 0x01; //setting analoge or digital and analog osc
CMCON = 0x07; // disable comprator on port a
ADCON0=0b00000001; // Set RA0 as analog input
}
void InitTimer1()
{
// T0CON = 0x21;
T0CON = 0x01;
TMR0IF_bit = 0;
TMR0H = 0xFF;
TMR0L = 0xFF;
TMR0IE_bit = 1;
INTCON = 0xC0;
}
void Interrupt()
{
if (TMR1IF_bit){
TMR0IF_bit = 0;
TMR0H = 0x00;
TMR0L = 0xFF;
asm bsf ADCON0,GO;//Start Conversion read analoge
while(ADCON0==0x03) // till analoge port is open for AN0
{
// s= 0.001*(ADRESH+(ADRESL<<8)) ; /*+(ADRESL<<8)); */
m= (ADRESH) ;
r= m+5;
}
}
}
void main()
{
int i=1,j=1,n=1,k=1,p=1,q=1,a=0;
unsigned long int m,r;
// bit a=0;
init_ports();
GP1_bit = 0;
GP2_bit = 0;
GP3_bit = 0;
GP4_bit = 0;
GP5_bit = 0;
InitTimer1();
while(1)
{
trig : GP5_bit = 0,i=0,j=0,p=0,q=0,a=0;
if(gp3_bit ==1) a=1;
while( a==1)
{
GP5_bit = 1;
if(gp2_bit==0 && gp1_bit==0)
{ k=6 ;
n=6;
}
else if(gp2_bit==0 &&gp1_bit==1)
{
k=200;
n=200;
}
else if(gp2_bit==1 &&gp1_bit==0)
{
k=20;
n=1200;
}
else if(gp2_bit==1 &&gp1_bit==1)
{
k=100;
n=1200;
}
asm CLRWDT ;
a=0;
for(j=1;j<=k;j++)
{
asm CLRWDT ;
for(i=1;i<= r;i++)
{
asm CLRWDT ;
GP5_bit = 0;
for(j=1;j<=n;j++)
{
asm CLRWDT ;
for(i=1;i<= r;i++)
{
if(gp3_bit ==0) goto trig;
asm CLRWDT ;
Delay_ms(10);
}
}
}
}
}
--- Updated ---
Circuit diagram
Attachments
Last edited: