Pic microcontroller speed control project requirements
- Pic16f877 microcontroller
- L293d h-bridge Motor driver Ic
- DC Motor or small fan
- Crystal 20MHz
- Push Buttons
- connecting wires
- Bread board or PCB
- Power Supply battery
Project Code
#include< htc.h>
#include< pic.h>
#define _XTAL_FREQ 20000000
void rundutycycle(unsigned int x );
#define s1 RA0
#define s2 RA1
#define s3 RA2
#define s4 RA3
#define s5 RA4
#define s6 RA5
void main()
{
ADCON1=0x06;
TRISA=0b111111;
TRISC2 = 0;
CCP1CON = 0x0C;
PR2 = 0xFF;
rundutycycle(512);
}
void rundutycycle(unsigned int dutycyc){
T2CON = 0x01;
T2CON |= 0x04;
while(1){
CCPR1L = dutycyc>>2;
CCP1CON &= 0xCF;
CCP1CON |= (0x30&(dutycyc<<4));
if(s1==1){dutycyc=172; }
if(s2==1){dutycyc=342; }
if(s3==1){dutycyc=512; }
if(s4==1){dutycyc=686; }
if(s5==1){dutycyc=858; }
if(s6==1){dutycyc=1020; }
dutycyc=dutycyc;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น