YES!
SUCCESS!
I finally got my Tiny-ICD2 to work.
Apparently, my Bluetooth Dongle’s program (BlueSoliel) was hogging my COM ports.
When I tried to point MPLAB towards a COM port, it wouldn’t be able to connect, because BlueSoliel kept connecting to it.
After removing BlueSoliel, everything started falling into place.
Here’s the revised, tested, and accuracy-confirmed blinker program:
[code]//============================ Timed LED Blinker ========================//
// This program blinks an LED hooked up to RA0 every 200ms. //
// It also blinks an LED hooked up to RA1 every second. //
// The Timer0’s 200ms intervals was calculated in the following way: //
// 1 second / 5Hz = 200ms interval. //
// 10,000,000Hz / 4 instructions = 2,500,000Hz //
// 2,500,000Hz / 32 (Prescalar) = 78125Hz. //
// 78125Hz / 5Hz = 15625 (# counts needed for 200ms timer0 intervals.) //
// 15625 in hexidecimal = 3D09. //
// Thus, TMR0H = 3D and TMR0L = 09. //
//=======================================================================//
//============================ Inclusions. ==============================//
#include <p18f4620.h> // Specify the micro’s library. //
#include <timers.h> // Timer library (OpenTimer function)//
//=======================================================================//
//============================ Configurations. ==========================//
#pragma config OSC = HSPLL // 10 MHz external OSC * 4. //
#pragma config FCMEN = OFF // Fail Safe Clock Monitor. //
#pragma config IESO = OFF // Internal External OSC Switch Over.//
#pragma config PWRT = OFF // Powerup Timer. //
#pragma config BOREN = OFF // Brownout Reset. //
#pragma config BORV = 3 // Brownout Voltage = lowest setting.//
#pragma config WDT = OFF // Watch Dog Timer. //
#pragma config WDTPS = 1 // Watch Dog Timer Post Scalar = 1:1.//
#pragma config MCLRE = ON // Memory Clear. //
#pragma config LPT1OSC = OFF // T1 OSC. //
#pragma config PBADEN = OFF // Port B Analog/Digital = Digital. //
#pragma config CCP2MX = PORTBE // CCP2 Multiplex with RB3. //
#pragma config STVREN = OFF // Stack Overflow Reset. //
#pragma config LVP = OFF // Low Voltage Programming. //
#pragma config XINST = OFF // XINST. //
#pragma config DEBUG = ON // Background Debugger. //
#pragma config CP0 = OFF // Code Protection Block 0. //
#pragma config CP1 = OFF // Code Protection Block 1. //
#pragma config CP2 = OFF // Code Protection Block 2. //
#pragma config CP3 = OFF // Code Protection Block 3. //
#pragma config CPB = OFF // Boot Block Code Protection. //
#pragma config CPD = OFF // Data EEPROM Code Protection. //
#pragma config WRT0 = OFF // Write Protection Block 0. //
#pragma config WRT1 = OFF // Write Protection Block 1. //
#pragma config WRT2 = OFF // Write Protection Block 2. //
#pragma config WRT3 = OFF // Write Protection Block 3. //
#pragma config WRTB = OFF // Boot Block Write Protection. //
#pragma config WRTC = OFF // Config Register Write Protection. //
#pragma config WRTD = OFF // Data EEPROM Write Protection. //
#pragma config EBTR0 = OFF // Table Read Protection Block 0. //
#pragma config EBTR1 = OFF // Table Read Protection Block 1. //
#pragma config EBTR2 = OFF // Table Read Protection Block 2. //
#pragma config EBTR3 = OFF // Table Read Protection Block 3. //
#pragma config EBTRB = OFF // Boot Block Table Read Protection. //
//=======================================================================//
//============================ Global constants. ========================//
#define TICKS_PER_SECOND 5 // Number of interrupts in 1 second. //
#define STATUS_LED PORTDbits.RD2 // Green LED on pin RD2. //
#define ERROR_LED PORTDbits.RD3 // Red LED on pin RD2. //
//=======================================================================//
//============================ Global variables. ========================//
int tick_counter = 0; // Create and zero a global counter. //
//=======================================================================//
//============================ Low-priority interupt setup. =============//
void timer0_handler (void); // Declare an empty function. //
#pragma code low_vector = 0x18 // Go to low_vector’s memory section.//
void timer0_vector (void) // Declare the setup function. //
{ //
_asm GOTO timer0_handler _endasm// Execute timer0_interupt function. //
} //
#pragma code // Return to original memory section.//
#pragma interruptlow timer0_handler // Redeclare the timer function as a //
// low priority interupt. //
//=======================================================================//
//============================ Main code. ===============================//
void main (void) //
{ //
OpenTimer0 (TIMER_INT_ON // Timer interupt enabled. //
& T0_SOURCE_INT // Lets timer0 trigger low interupts.//
& T0_16BIT // 16-bit mode. //
& T0_PS_1_32); // 1:32 post scalar. //
INTCONbits.GIE = 1; // Global interupts enabled. //
RCONbits.IPEN = 1; // Enable priority levels. //
TRISD = 0; // Set port D for output. //
while(1) // Infinite loop keeps micro running.//
{ //
// Interuptable processes goes here. //
} //
} //
//=======================================================================//
//============================ Low-priority interupt. ===================//
void timer0_handler (void) //
{ //
INTCONbits.TMR0IF = 0; // Reset timer0 interupt flag. //
TMR0H = 0x3D; // Reset the timer period. //
TMR0L = 0x09; // Reset the timer period. //
tick_counter++; // Count how many interupts occured. //
//
//
//
//================== Blink an LED really fast. =================// //
STATUS_LED = ~STATUS_LED; // Toggle the LED on and off. // //
//==============================================================// //
//
//
//
//================== Blink an LED more slowly. =================// //
if (tick_counter > TICKS_PER_SECOND) // //
// This is true every second. // //
{ // //
tick_counter = 0; // //
ERROR_LED = ~ERROR_LED; // Toggle the LED on and off. // //
} // //
//==============================================================// //
//
//
//
} //
//=======================================================================//
[/code]
Because everything divided in evenly, the one-second interval LED is accurate enough to set my clocks by.
Now, I can finally load the USART program that I’ve been working on and test it with HyperTerm.
::crosses fingers::