Hi
I'm trying to program PIC to generate two different square waves according to a switch state.
The first one is 1KHz with 0.5 duty cycle and the second is 5KHz with 0.2 duty cycle.
The first one is working but this is what I get for the second state.
And this is the code
Note:TCY is machine cycle and equals to 0.5 micro Second.
Mod edit: code tags
I'm trying to program PIC to generate two different square waves according to a switch state.
The first one is 1KHz with 0.5 duty cycle and the second is 5KHz with 0.2 duty cycle.
The first one is working but this is what I get for the second state.
And this is the code
C:
(
#include <p18F4520.h>
#include <xc.h>
#pragma config OSC=INTIO67,WDT=OFF,MCLRE=OFF
#include<Delays.h>
void main (void)
{
OSCCON=0x70;
ADCON1=0xF;
TRISA0=1;
TRISC0=0;
while(1)
{
while(RA0==1)
{
RC0=1;
Delay100TCYx(10);
RC0=(~RC0);
Delay100TCYx(10);
}
while(RA0==0)
{
RC0=1;
Delay100TCYx(0.8);
RC0=(~RC0);
Delay100TCYx(3.2);
}
}
}
Mod edit: code tags
Last edited by a moderator: