Reputation: 551
I have started PIC programming for PIC16F72 micro-controller through MPLAB X IDE and XC8 compiler.Below is my code, it is compiled successfully.
#define _XTAL_FREQ 4000000
#include<xc.h>
#pragma config FOSC = RC // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
char pattern[] = {0b10000001,0b11000011,0b11100111,0b11111111,0b11100111,0b11000011,0b10000001};
void write(char tab)
{
char check;
for(int a=0;a<8;a++)
{
check = ((tab >> a) & 1);
if(check)
{
PORTBbits.RB7=1;
PORTBbits.RB6=0;PORTBbits.RB6=1;
}
else
{
PORTBbits.RB7=0;
PORTBbits.RB6=0;PORTBbits.RB6=1;
}
}
}
void main(void) {
TRISB=0x00; //Initialize as output
PORTBbits.RB6=0;
PORTBbits.RB5=0;
PORTBbits.RB5=1;
while(1)
{
for(int i=0;i<7;i++)
{
write(pattern[i]);
__delay_ms(1000);
}
}
return;
}
When I simulated my code in Proteus it shows below error Processor has been reset by watch dog timer expiring at xxxxx after every 2.3 seconds.
I have searched for this problem with no success. I am unable to resolve the issue
Upvotes: 0
Views: 2587
Reputation: 68
Proteus, the simulation tool, is not officially provided by microchip (chip manufacturer), also sometimes the pirated copy of software creates issues, one thing you can try is double click on the microcontroller in Proteus and change the configuration word to what you actually want. I suggest you to test the code on physical microcontroller.
Upvotes: 0
Reputation: 1
You can try to use MPLAB X to generate configuration bits for you.
In MPLAB X, click Window -> PIC Memory Views -> Configuration Bits. New window will show up where you can configure your PIC and disable watchdog. If you click button "Generate Source Code to Output" MPLAB will generate source code with proper Configuration Bits for PIC you're using in project. Here's official Microchip tutorial which describes it in detail -http://microchipdeveloper.com/mplabx:view-and-set-configuration-bits
Upvotes: 0