ranga88
Newbie level 6
Hi all,
I'm new to microcontroller programming and I wrote a simple code for 16F628A to make a LED chaser with PORTA. But it is not workin as expected. I simulated it with proteus and it runs onetime and stops. When I change the same code to work with PORTB it works as expected. What could be the problem? I will post the code below. Thnx..
I'm new to microcontroller programming and I wrote a simple code for 16F628A to make a LED chaser with PORTA. But it is not workin as expected. I simulated it with proteus and it runs onetime and stops. When I change the same code to work with PORTB it works as expected. What could be the problem? I will post the code below. Thnx..
Code:
// PIC16F628A Configuration Bit Settings
// 'C' source line config statements
#include <xc.h>
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
#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)
#define _XTAL_FREQ 4e6
int delay = 500;
void MoveLeft()
{
while(RA4!=1)
{
PORTA=PORTA*2;
__delay_ms(delay);
}
}
void MoveRight()
{
while(RA0!=1)
{
PORTA=PORTA/2;
__delay_ms(delay);
}
}
void main()
{
CMCON=0x07;
TRISA=0x00;
PORTA=0b00011111;
__delay_ms(500);
PORTA=0b00000001;
__delay_ms(500);
while(1)
{
if(RA0==1)
MoveLeft();
if(RA4==1)
MoveRight();
}
}