I made a simple pic16f648a program (xc8 compiler) to display numbers from 0 to 9 on 7segLED. The xc8 program
is following:
#define __PICPRO__
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include
#define _XTAL_FREQ 10000000 //define crystal frequency to 20MHz
// This array stores binary bit pattern that will be send to PORTD
unsigned char binary_pattern[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void main(void)
{
TRISB = 0x00; //define PORTB as a output pin
while(1)
{
//this loop sends all binary patterns to PORTB
for (int i=0;i<10;i++)
{
PORTB = binary_pattern[i];
__delay_ms(1000); //add delay of one second
}
}
return;
}
The attached image shows the SimulIDE circuit.
The program works well when MCLR is set to HIGH (i.e. the switch is OFF).and stops working
However, when the SWITCH is ON, the circuit stops (LED becomes black) instead of starting from the beginning of the program.
What is wrong?
is following:
#define __PICPRO__
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include
#define _XTAL_FREQ 10000000 //define crystal frequency to 20MHz
// This array stores binary bit pattern that will be send to PORTD
unsigned char binary_pattern[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void main(void)
{
TRISB = 0x00; //define PORTB as a output pin
while(1)
{
//this loop sends all binary patterns to PORTB
for (int i=0;i<10;i++)
{
PORTB = binary_pattern[i];
__delay_ms(1000); //add delay of one second
}
}
return;
}
The attached image shows the SimulIDE circuit.
The program works well when MCLR is set to HIGH (i.e. the switch is OFF).and stops working
However, when the SWITCH is ON, the circuit stops (LED becomes black) instead of starting from the beginning of the program.
What is wrong?