Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

wierd problem with 16f628

Status
Not open for further replies.

eeanma

New Member
I'm trying to use 16f628's porta as an output but for some reason it doesn't work. at least when i'm simulating with mplab's simulator. the problem is that i cannot change the state of porta's 0-3 pins. They are always 0. so only RA4 is working.

my code is:

LIST P=16F628
radix hex
#include "P16F628.INC" ; Include header file

__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON



ORG 0x000 ; Program starts at 0x000

BSF STATUS,RP0 ; bank 1
CLRF TRISA ;all output
BCF STATUS,RP0 ; back to bank 0

CLRF PORTA

LOOP:
BSF PORTA,4 ;RA4 goes up
BCF PORTA,4 ;RA4 goes down
BSF PORTA,3 ;nothing happens
BSF PORTA,2 ;nothing happens
BSF PORTA,1 ;nothing happens
BSF PORTA,0 ;nothing happens
GOTO LOOP
END

can you see any clear errors or have you had same kind of problem??
Or is the error in simulator??

a
 

Exo

Active Member
PIC 16F628 has comparators on portA. They are ON by default, so if you want ,to use portA pins as normal I/O you must first turn the comparator off

Add the following lines to the top of your code

MOVLW 0x07
MOVWF CMCON
 
Status
Not open for further replies.

Latest threads

Top