introduction to using mplab and hi-tide group #9 josealex mikeroberto goto and print the file

12
Introduction to Using Introduction to Using MPLAB and Hi-tide MPLAB and Hi-tide Group #9 Group #9 Jose Jose Alex Alex Mike Mike Roberto Roberto Goto Goto http://www.alexhan.net/senior.html http://www.alexhan.net/senior.html and print the file and print the file

Upload: arleen-lawrence

Post on 28-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

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

Page 2: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print 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

Page 3: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

Program CodeProgram Code

Motor ControlMotor Control

IR SensorIR Sensor

Key DebouncerKey Debouncer

Page 4: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

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}}}}

Page 5: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

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;}}}}

Page 6: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

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

Page 7: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

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; }} }}

Page 8: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

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

Page 9: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

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

Page 10: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

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;

Page 11: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

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}}}}

Page 12: Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto  and print the file

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.