Here's the code, but this is more of a question.
My code seems to execute ok on the actual hardware, but when running on the simulator, it appears that setting the TMR0 prescaler has no effect on the TMR0 counter. I've tried setting OPTION = 000000, and it seems that TMR0 increments at the same rate when stepping through the program in the debugger (simulator) as it does when OPTION = 000111. Also setting a watch on OPTION seems to show it as 0x00 regardless of setting as well.
Is this a bug in the simulator? Or am I doing this wrong?
My code seems to execute ok on the actual hardware, but when running on the simulator, it appears that setting the TMR0 prescaler has no effect on the TMR0 counter. I've tried setting OPTION = 000000, and it seems that TMR0 increments at the same rate when stepping through the program in the debugger (simulator) as it does when OPTION = 000111. Also setting a watch on OPTION seems to show it as 0x00 regardless of setting as well.
Is this a bug in the simulator? Or am I doing this wrong?
Code:
/*
* File: Main1.c
* Author: Travis
*
* Created on May 18, 2020, 1:30 PM
*/
// CONFIG
#pragma config OSC = XT // Oscillator selection bits
#pragma config WDT = OFF // Watchdog timer enable bit
#pragma config CP = OFF // Code protection bit
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define _XTAL_ 4000000
#include <xc.h>
#include <stdlib.h>
#include <stdio.h>
const char (seg7set[11]) = {
0b00001000, //0
0b01101011, //1
0b01001000, //2
0b01000001, //3
0b00100011, //4
0b00010001, //5
0b00010000, //6
0b01001011, //7
0b00000000, //8
0b00000001, //9
0b01111111, //clear
};
const char (timer_m_values[8]) = {
3,
4,
5,
6,
7,
8,
9,
10
};
/*********************************************************
* Global Variables
* variables for clocks
**********************************************************/
int dotflash;
char previousclk = 0;
char ansel = 0;
/*********************************************************/
/*Function for advancing timer based clocks*/
void advanceclocks (void){
if (previousclk > TMR0) //advance item clocks here
{
dotflash++;
ansel++;
}
else
{
previousclk = TMR0;
}
}
void main(void) {
TRISA = 0b1010; //RA3 gets tri-stated to turn off AN1 and AN2,
//RA1 must be high imp. its connected straight to ground
OPTION = 000111; //Options - Prescaler set at 1:256
TRISB = 0b00000000; //All PortB Pins are I/O
char pba = 0b10000000; //PortB Anode This must be toggled to enable/disable the anode in port B (adds with portbset)
char time_s = 0; // timer
char digit = 0; // for setting each digit
RA3=1; //Anode 1 and 2 - tristate this pin to turn off
//PORTAbits.RA3=1; //this is here from previous attempts at troubleshooting, does the same as above.
RB7=1; //Anode 3 start on Anode 3, or the if statement flow doesnt work
while(1) {
//clocks
advanceclocks() ;
if (dotflash==4000) //4000 cycles is approx 1s
{
if (RA0==1) RA0=0;
else if (RA0==0) RA0=1;
dotflash=0;
}
if (ansel>15) // This is the display multiplexor
{
if (RB7==1)
{
//clear the display
RB7=0;
pba=0b00000000;
TRISA = 0b0010;
RA3=1;
//activate display
}
else if (RA3==1)
{
//clear the display
RA3=0;
//activate display
}
else if (RA3==0)
{
TRISA = 0b1010;
RB7=1;
pba=0b10000000;
//activate display
}
ansel=0;
}
// end of display multiplexor
if (RA1==0)
{
PORTB = seg7set[0]+pba;
}
else
{
PORTB = seg7set[3]+pba;
}
}
return;
}
Last edited: