110 likes | 247 Vues
This guide introduces the use of MPLAB and Hi-Tide for programming microcontrollers, focusing on the essential setup and coding practices. You'll learn about creating and transferring code, coding for motor control, IR sensors, and implementing key debouncer functionality. Examples include LED flashing routines with interrupts and motor control techniques utilizing peripherals. Whether you're emulating Linux with Cgywin or using PICC Lite for code conversions, this overview will get you started on your microcontroller projects effectively. ###
E N D
Introduction to Using MPLAB and Hi-tide Group #9 Jose Alex Mike Roberto Goto http://www.alexhan.net/senior.html and print the file
Purpose of Programs • Cgywin is to emulate Linux to run the other programs • Picc lite and Hi-tide are the environment to write your code for programming the microcontroller and converts to Hex • MPLAB is software that allows the codes to be transferred to the microcontroller
Program Code • Motor Control • IR Sensor • Key Debouncer
LED On #include "init.h"// included by C-Wiz #include <htc.h> void main(void) { init();// Function call inserted by C-Wiz while (1){ RA0=1; //TODO Auto-generated main function } }
LED flashing 5 sec int i,k; void main(void) { init();// Function call inserted by C-Wiz while (1){ k=0; while (k<1000){ i=0; k++; while (i<1500){ i++;} } RA0=RA0^1; } }
LED Flashing w / Interrupts // Interrupt service routines #include <htc.h> externint k; void interrupt my_isr(void){ /***** Timer 1 Code *****/ if((TMR1IE)&&(TMR1IF)){ if(k>50) { k=0; RA0=RA0^1; } else k++; TMR1IF=0;// clear event flag } }
Conflict With Loop 5 Second LED flip-flop And Key Debouncer running in main.c
Key Debouncer i = 0; // Wait 20 ms for Button Down while (i < Twentyms) if (1 == RA3) // Button Up / Start over i = 0; else // Button Down /Increment Count i = i + 1;
Motor Control main(void) { init();// Function call inserted by C-Wiz while (1){ RA0=RA0^1; i=0; while(i<10) { i++; k=0; while(k<3000) {k++;}} //CCPR1L= 0b01111111; A=A+1; CCPR2L= A; if(CCPR2L==0XFF) CCPR1L=~CCPR1L;
IR Sensor #include "init.h"// included by C-Wiz #include <htc.h> void main(void) { init();// Function call inserted by C-Wiz while (1){ if(RB2==1) RA0=0; else RA0=1; //TODO Auto-generated main function } }
The End Thanks Ya’ll Email or get in touch with us for more information or questions.