PIC12F675 motor control program example source code

Publisher:LogicLeaperLatest update time:2019-10-30 Source: 51heiKeywords:PIC12F675 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The compiler used is PICC9.83

You can try it, but you must turn off AD.

//***************************************************

//__________________

// VDD-| 1 14 |-VSS

// Motor GP5-| 2 13 |-GP0/AN0/DAT LED

// AN3/GP4-| 3 12 |-GP1/AN1/CLK  

//GP3/RMCLR--| 4 11 |-GP2/AN2  

// |________________ |

//16F675

//***************************************************



#include


#define uchar unsigned char 

#define uint unsigned int 



#ifndef OPEN

#define OPEN 1

#endif


#ifndef OFF

#define OFF 0

#endif



#define SET 1

#define CLEAR 0

#define TRUE 1

#define FALSE 0



__CONFIG(FOSC_EXTRCIO & WDTE_OFF & MCLRE_OFF & BOREN_OFF & CP_OFF ​​& PWRTE_ON);

  //Internal RC watchdog is turned off GP3 is IO code is not protected

//#pragma config BOREN = OFF, CPD = OFF, FOSC = XT, MCLRE = OFF, WDTE = OFF, CP = OFF, PWRTE = OFF



#define KEY GPIO3

#define LED GPIO0

#define BEEP GPIO1

#define SCR GPIO5

#define GHG GPIO4



  /*********Program declaration****************/

void InitAPP(void);


//void ScanKey();




void InitAPP()

{

        /* Comment out if using simulator, ICD2, or ICE2000

        #asm //Load Factory Calibration Value Into OSCCAL

                call 0x3FF

                bsf_STATUS,5                                                                         

                movwf _OSCCAL                                                

        #endasm

        */


    TRISIO=0x00; //Set All I/O's As OUT  

        VRCON = 0; //Reference voltage power off

        CMCON = 0x07; // configure comparator inputs as digital I/O                   

        ANSEL = 0; // configure A/D inputs as digital I/O

        ADON = 0;        

        GIE = ​​1;



                             //Enable All Interrupts

  //RAPU=0; //Pull-up always enabled

  // WPUA5=1; //RA5 enable  

   // RAIE=1;

     IOCB5=1; //Pin interrupt enable


}

/*********Timer initialization***************/

void TimeInt()  

{

    OPTION_REG &= 0x80; //

    TMR0 = 0x14; // 250uS

    T0IE = 1; //Timer0 Overflow Interrupt Enabled

    T0IF = 0; //Clear Timer0 Overflow Interrupt Flag 


}    


//***************************************************************************

//Isr() - Interrupt Service Routine

// - Timer0 Overflow & GP3 Pin Change Are Used

//***************************************************************************


void interrupt Isr()

{ static uint count;

        if ( (T0IE & T0IF) == 1) //If A Timer0 Interrupt, Then

        {     

                 TMR0 = 0x14; 

                 if(++count==40)  

                    {

                     count=0;

                 LED=~LED;

                      }


                    T0IF = 0; //Clear Timer0 Interrupt Flag

      }

/*

   else if ( (GPIE & GPIF) == SET) //If A GP3 Pin-Change Interrupt

    {

     if(GHG==0)

      {

       SCR = 1; // Turn off the motor

       BEEP=0; //Turn on the buzzer   

      }

     else if(GHG==1)

     {

      SCR=0; //Turn on the motor

      BEEP=1; //Turn off the buzzer   

     }

       GPIF=0; 


    }


        else if ( (INTE & INTF) == SET) //If A GP2/INT External Intrrupt

        {


        }

        else if ( PEIE == SET) //If Peripheral Interrupts Enabled, Check Peripheral

        { //Interrupts


                if ( (EEIE & EEIF) == SET) //If A EEPROM Interrupt

                {


                }

                else if ( (ADIE & ADIF) == SET) //If AA/D Converter Interrupt

                {


                }


                else if ( (CMIE & CMIF) == SET) //If A Comparator Interrupt

                {


                }

                else if ( (TMR1IE & TMR1IF) == SET) //If A Timer1 Interrupt

                {


                }

        }



***************************/


}



//*********************************************************************************

//Main() - Main Routine

//*********************************************************************************


void main()

{   

    InitAPP(); 

    TimeInt();         

        while(1)                             

          {


      }                


}


Keywords:PIC12F675 Reference address:PIC12F675 motor control program example source code

Previous article:A simple SPI applet for PIC microcontroller
Next article:HC-SR04 ultrasonic module 51+PIC microcontroller routine

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号