PORTD = DigitsBuf[0];
PORTD = DigitsBuf[9];
Remember that the discrete flashing LEDs are 'segments' in a 'digit'. When the entire 10 digit (9*7segment LEDs + 1 group of discrete LEDs mapped as the 10th digit) display. RE1 is the digit select for the discrete LEDs. Since our multiplexer consists only of the discrete LEDs, I left that out. If you have wired the discrete LEDs as the 10th digit (with RE1 as the 'digit select') then turn it on to select the LEDs. (My test version assumes that the anodes of the LEDs are on PORTD and the cathodes are connected to ground - through the appropriate resistor). This setup is sufficient to debug all of the timer/interrupt stuff and gain experience with how to use this design paradigm.By the way..
The 10th digit is at RE1
We are crossing posts but PORTD = DigitsBuf[0]; will output the decoded 7segment pattern of the MSdigit of SystemTime_Secs to the discrete LEDs - the 6 segs lit is what you would expect when the MSdigit is 0, yes? Because we have not yet implemented the sequential digit select function, its one digit per build. The rest of the mux should happen right after sorting out the hardware/config/oscillator issues.And PortD 0 to 5 are lit.
That is because the Sound_Play code uses dumb delays as I suspected. So when you play that cute sound, your system can do nothing else while the beep is beeping, including polling the derived timer that drives the flashing LED.OK, another funny thing.
When I switch off and on the easyPIC power sw the buzzer is messed up and flashing is slow.
void main() {
initIO();
initLEDdisplay(); // init multiplexer
initTimers(); //Init Timers
Sound_Init(&PORTC, 3); // for looking at compiled code only!
Sound_Play(1000, 100);
Volts = 456;
From #36:I do display multiplexing in the interrupt.
That's where it will be if we get theremove that statement to the TIMER 0 service code where it says //Display Multiplex Code goes here. That will be the starting point of the whole display mux.
and now no lit leds.PORTD = DigitsBuf[9];
Does not do anything.Then, experiment with this line:
LEDs_toggle(GREEN_LED + YELLOW_LED);
short k;
// copy IO definitions and initIO() from the original code i.e.
// PORTD is a digital output- this test will help identify problems with
// the initIO function.
main(){
initIO()// the same one for the other code
k = 0;
while(1){
PORTD = k;
k++;
Delay_ms(50);
}//while
MikroC has an ICD, but I'm the wrong person to ask. I haven't bothered to use a debugger in about 7 or 8 years....
I dunno about mikroICE. It has hardware microProg debugger and it can step through the code in real time I believe.
RB knows about that stuff far better than me .
He can explain this stuff better.
...
while(1)
{
PORTB = 0xFF; // flashes PORTB LEDs at very close to 1Hz
Delay_mS(100);
PORTB = 0x00;
Delay_mS(900);
}
That's a great idea.Personally I like to do this and compare the flash rate to a ticking house clock;
Maybe. But TMR1 is working OK and I'm guessing that he might want to drive the buzzer with the PWM. The MicroC library routines for the buzzer use dumb delays that will make for a sluggish system or require moving more stuff to the interrupt routines which I would discourage - especially on midrange. Just my .02Then get the TMR2 int going at 1mS per interrupt (as previously discussed).
/*
PIC 16F887.
HS 8MHz Oscillator
/* Config setting for reference (set by compiler)
CONFIG1 0x2BF2, b'00101011 11110010'
CONFIG2 0x0600, b'00000110 00000000'
Config -- Brown Out at 2.1V
HS Osc
Clock Fail safe enabled.
*/
/*****************************************************************************/
/*********** Variables ****************************/
unsigned int Volts,Amps,Time; // Voltage, Ampere and Timer Vars.
short SysTIK_LEDtimer; // sysTIK timer for LED (as an example)
short SecsTimerPS; // prescaler for seconds derived timer
bit SecElapsed; // set by sysTIK when one second has elapsed
unsigned int SystemTime_Secs; // system Time runs in seconds
/* TMR0 Set up Values (interrupt at 3ms)*/
#define Option_Reg_init 0b10000101// Clock at Tcyc/64 Prescaler assigned to TMR0,
// RBPU off
// Setting is 256 - (3ms / .5usTcyc) / 64Prescaler = 256 - 93.755 counts = 162.25 ~= 162
#define TMR0_Set 162 // counts 162->255 then rolls over and interrupts
/*TMR1 Set up values (interrupt at 1s)*/
#define T1CON_init 0b00110000 // no gate, internal Tcyc/8, timer STOPPED
#define CCP1CON_init 0b00001011 // compare CCPR1 to TIMER1, IRQ and reset TMR1 on match
#define CCPR1_init 1250 // 0.5usTcyc *8 Prescale * 1250 = 5msec
#define SecsTimerPrcSet 200 // 200 * 5ms sysTIK = 1 sec
#define LED_Flash_TimeSet 20 // about 5ms*20 = 100ms flash time
void initTimers(){
INTCOn = 0x00; // No interrupts whatsoever.
OPTION_REG = Option_Reg_init; // Load Option Register value(defined)
TMR0 = TMR0_Set; // Load Timer 0 value(defined)
T1CON = T1CON_init; // Timer 1 OFF
TMR1H = TMR1L = 0; // Timer counts UP to CCP value (no 16bit definition in MicroC)
CCPR1 = CCPR1_init; // Load CCPR1 value(defined
CCP1CON = CCP1CON_init; // Set up the CCP
/* Initaite derived timers*/
SecsTimerPS = SecsTimerPrcSet;// Initiate seconds timer prescaler
SecElapsed = 0; // Reset flag
SysTIK_LEDtimer = 0; // Reset LED Timer
/* Fire it up */
TMR1IF_bit = 0; //PIR1 Reg; Clear the Timer1 overflow Interrupt flag bit
CCP1IF_bit = 0; //Clear Timer1 Interrupt flag
T1CON.TMR1ON = 1; //Start timer 1
/* Then Enable Interrupts */
TMR1IE_bit = 1;
CCP1IE_bit = 1;
INTCON.T0IE = 1;
INTCON.PEIE = 1; //Enable Peripheral Interrupts
INTCON.GIE = 1; //Enable Global Interrupts
}
/******** INTERRUPT ************************************/
void interrupt(){
/* This is Timer 1 interrupt */
if (CCP1IE_bit) // System Tik
if (CCP1IF_bit){ // Interrupt on Timer1 = CCP
CCP1IF_bit = 0; // Ack IRQ
if (SysTIK_LEDtimer) SysTIK_LEDtimer--;// Decrement derived timers
SecsTimerPS--; // Decrement Seconds timer prescaler
if(SecsTimerPS == 0){ // If one second passed.....
SecsTimerPS = SecsTimerPrcSet;// Reload the prescaler
SecElapsed = 1; // signal main program
}
// more code goes here
PORTA = 0xFF;
PORTB = 0xFF;
PORTC = 0xFF;
PORTD = 0xFF;
PORTE = 0xFF;
delay_ms(100);
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
delay_ms(900);
}
}
/* IO Initializing Routine */
void initIO(){
ANSEL = 0x00;
ANSELH = 0x00; // Rest are Digital IO's.
CM1CON0.C1ON = 0; // Disable Comparator 1.
CM2CON0.C2ON = 0; // Disable Comparator 2.
PORTA = 0; // Clear PORTs.
PORTB = 0; // Clear PORTs.
PORTC = 0; // Clear PORTs.
PORTD = 0; // Clear PORTs.
PORTE = 0; // Clear PORTs.
TRISA = 0;
TRISB = 0;
TRISC = 0;
TRISD = 0;
TRISE = 0;
}
/********** MAIN ********************************/
void main(){
initIO(); // Initialize IO's
initTimers(); // Initialize the Timers
while(1){
}
}
if (CCP1IE_bit) // System Tik
should that be;
if (CCP1IE_bit) { // System Tik
// this is hard to check visually
while(blah) {
stuff;
}
// this is much better for checking visually
while(blah)
{
stuff;
}
by Duane Benson
by Aaron Carman
by Duane Benson
by Aaron Carman