# how to generate a square wave on PIC16F688 ?

#### ttuna10

Joined Feb 4, 2016
4
This is rather a simple question.
I'm trying to generate a square wave by using PIC16F688. I'm using PIC C compiler and Proteus 7 .This is my microcontroller on Proteus :
. So this might a basic question because i'm a newbie on pic programming. I hope someone help me out .
Thanks.

#### ISB123

Joined May 21, 2014
1,236
Simply cycling the output pin between HIGH and LOW would give you a square wave. PWM would be something different.

#### R!f@@

Joined Apr 2, 2009
9,740
Welcome to AAC

You can use delays and toggle an output quite easily.

#### ttuna10

Joined Feb 4, 2016
4
Simply cycling the output pin between HIGH and LOW would give you a square wave. PWM would be something different.
thanks for the answer. As i said because of i really don't know how to program it .I should know the code. My question is what's the code?

#### nerdegutta

Joined Dec 15, 2009
2,676
Hi, is this homework?

Show us the whole schematic, and tell us what you think you have to do, and what you have done.
Which PIC C compiler are you using?

#### ISB123

Joined May 21, 2014
1,236
Code:
void main()
{
TRISA=0X00;
PORTA=0X00;
while(1)
{
PORTA=0XFF;
__delay_ms(1000);
PORTA=0X00;
__delay_ms(1000);
}
}

#### saurav2220

Joined Feb 4, 2016
1
If you are new, there is an Embedded Systems class on edx for free that teaches you the basics. The course already started, so not sure if you can join but all the materials are on their website. The following link talks about ports/pin so it might help you even though they are using a TM4C micro, the theory behind it is the same.

http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C6_MicrocontrollerPorts.htm

#### ttuna10

Joined Feb 4, 2016
4
Hi, is this homework?

Show us the whole schematic, and tell us what you think you have to do, and what you have done.
Which PIC C compiler are you using?
Hi, is this homework?

Show us the whole schematic, and tell us what you think you have to do, and what you have done.
Which PIC C compiler are you using?

So this is my circuit and for compiler i'm using MPLAB IDE. I'm trying to control these power mosfets by using PIC16F688. I should control the mosfets like these first Q1 and Q4(at the same time) should conduct then Q2 and Q3(at the same time) should.After i controled the mosfets then while Q1 AND Q4 are conducting DC motor (at the middle of the power mosfets) should turn to the right or left but it should be opposite to the Q2 AND Q3 conducting.( i mean the direction (to the left or right) ). Our tutor said i can use pwm .He said we can change the duty cycle of the waves(stuff like that) and then can control where dc motor is going to turn.
As you can see on schematic i labeled the RA0,RA1,RA2 and RA4 pins as the same as the input of the circuit .That is to say i labeled Q1 ,Q2 ,Q3 and Q4 as an input of the circuit and as an 13,12,11 and 4 pins of the PIC16F688 so that when i control the PIC i will control the mosfets.That's it . Can you briefly show me how can control mosfets by writing code into PIC and how to use PWM in that code ?

Thanks guys and sorry about my grammar mistakes

Last edited:

#### ttuna10

Joined Feb 4, 2016
4
If you are new, there is an Embedded Systems class on edx for free that teaches you the basics. The course already started, so not sure if you can join but all the materials are on their website. The following link talks about ports/pin so it might help you even though they are using a TM4C micro, the theory behind it is the same.

http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C6_MicrocontrollerPorts.htm
Thanks for the reply man. Can you suggest me any other sites that i can learn PIC ?

#### Picbuster

Joined Dec 2, 2013
1,025
This is rather a simple question.
I'm trying to generate a square wave by using PIC16F688. I'm using PIC C compiler and Proteus 7 .This is my microcontroller on Proteus :
View attachment 100014. So this might a basic question because i'm a newbie on pic programming. I hope someone help me out .
Thanks.
make an interrupt using trm0 put tris RC1 =0 and the ints TMR0IE=1; GIE=1;
i
if (TMR0IF)
{
TMR0IF=0;
RC1=!RC1; // here is your block wave at pin RC1.
}

To make it slower do
if (TMR0IF)
{
TMR0IF=0;
cnt++;
if ( cnt>wanted_time)
{
cnt=0;
RC1=!RC1; // here is your block wave at pin RC1.
}
}