introduction to using mplab and hi-tide group #9 josealex mikeroberto goto and print the file
Post on 28-Dec-2015
213 Views
Preview:
TRANSCRIPT
Introduction to Using Introduction to Using MPLAB and Hi-tideMPLAB and Hi-tide
Group #9Group #9JoseJose AlexAlexMikeMike RobertoRoberto
Goto Goto http://www.alexhan.net/senior.htmlhttp://www.alexhan.net/senior.html and and print the fileprint the file
Purpose of ProgramsPurpose of Programs
Cgywin is to emulate Linux to run the Cgywin is to emulate Linux to run the other programsother programs
Picc lite and Hi-tide are the environment to Picc lite and Hi-tide are the environment to write your code for programming the write your code for programming the microcontroller and converts to Hexmicrocontroller and converts to Hex
MPLAB is software that allows the codes to MPLAB is software that allows the codes to be transferred to the microcontrollerbe transferred to the microcontroller
Program CodeProgram Code
Motor ControlMotor Control
IR SensorIR Sensor
Key DebouncerKey Debouncer
LED OnLED On
#include#include "init.h"// included by C-Wiz "init.h"// included by C-Wiz#include#include <htc.h> <htc.h>
voidvoidmain(main(voidvoid)){{init();// Function call inserted by C-Wizinit();// Function call inserted by C-Wizwhilewhile (1){ (1){RA0=1;RA0=1;////TODOTODO Auto-generated main function Auto-generated main function}}}}
LED flashing 5 secLED flashing 5 secintint i,k; i,k;voidvoidmain(main(voidvoid)){{init();// Function call inserted by C-Wizinit();// Function call inserted by C-Wizwhilewhile (1){ (1){k=0;k=0;whilewhile (k<1000){ (k<1000){i=0;i=0;k++;k++;whilewhile (i<1500){ (i<1500){i++;}i++;}}}RA0=RA0^1;RA0=RA0^1;}}}}
LED Flashing w / InterruptsLED Flashing w / Interrupts #include#include "init.h"// included by C-Wiz "init.h"// included by C-Wiz #include#include <htc.h> <htc.h> intint k; k; doubledouble maxval = 1000; maxval = 1000; intint f; f; intint i; i; constconst intint Twentyms = 1150; // Declare a Constant for 20 ms Delay Twentyms = 1150; // Declare a Constant for 20 ms Delay voidvoid main(main(voidvoid)) {{ k=0;k=0; init();// Function call inserted by C-Wizinit();// Function call inserted by C-Wiz
whilewhile(1 == 1) // Loop Forever(1 == 1) // Loop Forever {{ i = 0; // Wait 20 ms for Button Upi = 0; // Wait 20 ms for Button Up whilewhile (i < Twentyms) (i < Twentyms) {{ ifif (0 == RE2) // Button Down/Start over (0 == RE2) // Button Down/Start over {{ i = 0;i = 0; }} elseelse // Button Up/Increment Count // Button Up/Increment Count {{ i = i + 1;i = i + 1; } // fi} // fi } // elihw} // elihw
NOP();NOP(); i = 0; // Wait 20 ms for Button Downi = 0; // Wait 20 ms for Button Down whilewhile (i < Twentyms) (i < Twentyms) ifif (1 == RE2) // Button Up/Start over (1 == RE2) // Button Up/Start over i = 0;i = 0; elseelse // Button Down/Increment Count // Button Down/Increment Count i = i + 1;i = i + 1;
RB1 = RB1 ^ 1; // Toggle RA5 to Turn ON/OFF LEDRB1 = RB1 ^ 1; // Toggle RA5 to Turn ON/OFF LED
} // elihw} // elihw } // End cDebounce} // End cDebounce
Conflict With LoopConflict With Loop #include#include "init.h"// included by C-Wiz "init.h"// included by C-Wiz #include#include <htc.h> <htc.h> intint i,k,j; i,k,j; constconst intint Twentyms = 1150; // Declare a Constant for 20 ms Delay Twentyms = 1150; // Declare a Constant for 20 ms Delay voidvoid main(main(voidvoid)) {{ init();// Function call inserted by C-Wizinit();// Function call inserted by C-Wiz whilewhile (1){ (1){ k=0;k=0; whilewhile (k<1000){ (k<1000){ i=0;i=0; k++;k++; whilewhile (i<1500){ (i<1500){ i++;}i++;} }} RA0=RA0^1;RA0=RA0^1;
j = 0; // Wait 20 ms for Button Upj = 0; // Wait 20 ms for Button Up whilewhile (j < Twentyms) (j < Twentyms) {{ ifif (0 == RE2) // Button Down/Start over (0 == RE2) // Button Down/Start over {{ j = 0;j = 0; }} elseelse // Button Up/Increment Count // Button Up/Increment Count {{ j = j + 1;j = j + 1; }} }}
NOP();NOP(); j = 0; // Wait 20 ms for Button Downj = 0; // Wait 20 ms for Button Down whilewhile (j < Twentyms) (j < Twentyms) ifif (1 == RE2) // Button Up/Start over (1 == RE2) // Button Up/Start over j = 0;j = 0; elseelse // Button Down/Increment Count // Button Down/Increment Count j = j + 1;j = j + 1;
RB1 = RB1 ^ 1; RB1 = RB1 ^ 1; }} }}
Key De-bouncerKey De-bouncer //trial debouncer//trial debouncer #include#include "init.h"// included by C-Wiz "init.h"// included by C-Wiz #include#include <htc.h> <htc.h> intint i; i; constconst intint Twentyms = 1150; // Declare a Constant for 20 ms Delay Twentyms = 1150; // Declare a Constant for 20 ms Delay main()main() {{ init();// Function call inserted by C-Wizinit();// Function call inserted by C-Wiz
whilewhile(1 == 1) // Loop Forever(1 == 1) // Loop Forever {{ i = 0; // Wait 20 ms for Button Upi = 0; // Wait 20 ms for Button Up whilewhile (i < Twentyms) (i < Twentyms) {{ ifif (0 == RE2) // Button Down/Start over (0 == RE2) // Button Down/Start over {{ i = 0;i = 0; }} elseelse // Button Up/Increment Count // Button Up/Increment Count {{ i = i + 1;i = i + 1; } // fi} // fi } // elihw} // elihw
Key De-bouncer Cont.Key De-bouncer Cont. NOP();NOP(); i = 0; // Wait 20 ms for Button Downi = 0; // Wait 20 ms for Button Down whilewhile (i < Twentyms) (i < Twentyms) ifif (1 == RE2) // Button Up/Start over (1 == RE2) // Button Up/Start over i = 0;i = 0; elseelse // Button Down/Increment Count // Button Down/Increment Count i = i + 1;i = i + 1;
RA0 = RA0 ^ 1; // Toggle RA5 to Turn ON/OFF LEDRA0 = RA0 ^ 1; // Toggle RA5 to Turn ON/OFF LED // RB4 = RB4 ^ 1; // Toggle RA5 to Turn ON/OFF LED// RB4 = RB4 ^ 1; // Toggle RA5 to Turn ON/OFF LED RB1 = RB1 ^ 1; // Toggle RA5 to Turn ON/OFF LEDRB1 = RB1 ^ 1; // Toggle RA5 to Turn ON/OFF LED
} // elihw} // elihw } // End cDebounce} // End cDebounce
Motor ControlMotor Controlmain(main(voidvoid))
{{
init();// Function call inserted by C-Wizinit();// Function call inserted by C-Wiz
whilewhile (1){ (1){
RA0=RA0^1;RA0=RA0^1;
i=0;i=0;
whilewhile(i<10)(i<10)
{{
i++;i++;
k=0;k=0;
whilewhile(k<3000) (k<3000)
{k++;}}{k++;}}
//CCPR1L= 0b01111111;//CCPR1L= 0b01111111;
A=A+1;A=A+1;
CCPR2L= A;CCPR2L= A;
ifif(CCPR2L==0XFF)(CCPR2L==0XFF)
CCPR1L=~CCPR1L;CCPR1L=~CCPR1L;
IR SensorIR Sensor#include#include "init.h"// included by C-Wiz "init.h"// included by C-Wiz#include#include <htc.h> <htc.h>
voidvoidmain(main(voidvoid)){{init();// Function call inserted by C-Wizinit();// Function call inserted by C-Wizwhilewhile (1){ (1){ifif(RB2==1)(RB2==1)RA0=0;RA0=0;elseelseRA0=1;RA0=1;
////TODOTODO Auto-generated main function Auto-generated main function}}}}
The EndThe End
Thanks Ya’llThanks Ya’ll
Email or get in touch with us for more Email or get in touch with us for more information or questions.information or questions.
top related