benaddi6,
Using a CCS compiler, (with this great site, no need to help you there).
Try this code for a 18F4423, just change the #include on line 1 for your device.
This example of coding technique is quite poor from a professional point of view, I am sure of that !!.
Many comments within to explain, Please Read through the code. Do have fun with the knobs.
Hope your coding days will evolve as mine has through the years. I will try to be here more often for questions.
Caveman
PS. It worked in Proteus.
//#include "16f877.h" // OR WHAT EVER YOU CHOOSE
#include "18f4423.h" // CHANGE THIS for your needs
int16 isr_10m_your_delay; // this is a GLOBAL variable (16 bits), with a name given
// The next line controls the timing
#define YOUR_10M_DELAY_TIME 100 // CHANGE FROM "100" to suit your needs.
// Here is the "reading" of many books part. ahh.. , I will leave that up to you, , The Powerful Interrupt
#int_timer0
void ISR_TIMER0(){
set_timer0( 15535 ); // reload timer for 10 mS, just simple math.. pre-scaler setting and this count
if (isr_10m_your_delay) isr_10m_your_delay --; // decrement if NOT zero this time of the interrupt
}
void main(void) {
setup_timer_0( RTCC_INTERNAL | RTCC_DIV_2 ); // get TMR0 initialized for the time base
enable_interrupts( INT_TIMER0 ); // Allow the INT from TMR0
enable_interrupts( GLOBAL ); // Allow Interrupts, without GLOBAL, never an Int at all
// Initialize the delay
isr_10m_your_delay = YOUR_10M_DELAY_TIME;
for ( ;; ) {
if ( isr_10m_your_delay == 0 ) {
// Pick your pin in the physical realm
output_toggle(PIN_B4); // CHANGE ME FROM "PIN_B4"
// Re-Initialize the delay
isr_10m_your_delay = YOUR_10M_DELAY_TIME;
}
}
}