Items:
1 PC (Windows 7)
2 Internet access
3 PICkit 3 clone US$ 11.24
4 PIC18F46K22 US$ 3.60
6 Breadboard, connectors, LEDs, resistors etc
7 74HC164
8 LCD 1602
Setup:
Read PIC18F46K22 Datasheet
Install MPLAB X IDE and XC8
Insert the PIC18F46K22 microcontroller on the breadboard;
Make the 5 connections between the microcontroller and the PICkit3:
(Vdd, Ground, /Mclr, PgC and PgD. Pin 6 is not used.
Pull up /MClr with a resistor. Connect an LED with a resistor to ClkO.)
Connect the PICkit3 to the computer.
Programming:
Launch the X IDE
Create a standalone project for PIC18F46K22 using PICkit3 and XC8
Customise PICkit3 in the 'Set Configuration' :
Use low voltage programming in 'Program options'
Power target circuit from PICkit3 and 4.75 V in 'Power'
Edit a program and 'Make and Program Device'
Configuration Bits
Go to Window|PIC Memory views|Configuration Bits|
Select the appropriate options
Then 'Generate Source Code to Output'
Copy the required pragma's to the program
Notes on the Examples:
T10 Test X IDE, XC8 and downloading.T11 Turn on internal oscillator with clockout on ClkO, connected LED will be dimly lighted.
T12 Classical approach: Turn on some LEDs connected to the 8-bit port D.
T14 Changing LED patterns, with software delay.
T22 Timer 2 high-priority interrupt (draft, working)
Examples:
==========
// T10.c
int main(void){
while(1);
}
==========
// T11.c
#pragma config FOSC = INTIO7 // Oscillator Selection bits (Internal oscillator block, CLKOUT function on OSC2)
int main(void){
while(1);
}
==========
// T12.c
#include <pic18f46k22.h>
#pragma config FOSC = INTIO7 // Oscillator Selection bits (Internal oscillator block, CLKOUT function on OSC2)
int main(void){
LATD = 0x53; // Port D output = 0101 0011
TRISD = 0x00; // Port D all outputs
while(1);
}
==========
// T14.c
#include <pic18f46k22.h>
#pragma config FOSC = INTIO7 // Oscillator Selection bits (Internal oscillator block, CLKOUT function on OSC2)
int main(void){
int i;
LATD = 0x53; // Port D output = 0101 0011
TRISD = 0x00; // Port D all outputs
while(1){
for(i=0;i<=1000;i++);
LATD++;
}
}
==========
// T22.c Timer 2 high-priority interrupt#include <pic18f46k22.h>
#pragma config FOSC = INTIO7 // Oscillator Selection bits (Internal oscillator block, CLKOUT function on OSC2)
#pragma config WDTEN = OFF // Watchdog Timer Enable bits (Watch dog timer is always disabled. SWDTEN has no effect.)
int main(void){
int i;
LATD = 0x53; // Port D output = 0101 0011
TRISD = 0x00; // Port D all outputs
T2CON = 0x06 ; // Timer 2 ON, Prescaler 16
RCON |= 0x80 ;
IPR1 |= 0x02 ;
PIE1 |= 0x02 ;
PIR1 &= ~(0x02); // clear this interrupt condition
INTCON |= 0x80 ;
// ei();
while(1){
;
}
}
void high_priority interrupt T2ISR(void)
{
// only process timer-triggered interrupts
// if(INTCONbits.TMR0IE && INTCONbits.TMR0IF) {
LATD++;
PIR1 &= ~(0x02); // clear this interrupt condition
}
==========
No comments:
Post a Comment