16f628a Simple Program Code

16f628a Simple Program Code 4,7/5 6036 votes

It is a strange way of reversing the LED direction and as pointed out, you have to beware of the RA4 open drain issue. It needs a pull-up or it will constantly be read as zero.

Simple

I suspect your underlying problem is what we call RMW (Read Modify Write). When you read the state of the port pins you get the voltage levels on them at the instant of the read taking place. It is quite possible that capacitive charge on the pins and any circuit attached to them is delaying the change of logic level and you are reading it before it has stabilized.

Code that directly manipulates bits in a port will always be prone to this problem and it is the reason Microchip introduced the LAT registers in later PICs. A far better method is to move the bits in a variable then write that variable to to port, this ensures you never read the port at all so avoiding the problem. Another problem could be the 'PORTA=PORTA/2;' instruction. I think you intend it to shift the bits one place to the right but you ignore that RA5 will be shifted into RA4. I'm not sure why you make all the PORTA pins outputs then use them as inputs.

The instruction 'if(RA0==1)' and the equivalent for RA4 are reading the state of the pins but they are in output mode. Incidentally, you might find the >> and. Are you using 4 MHz INTOSCIO? How should the LEDs turn ON and OFF? - - - Updated - - - I have attached two versions of code. One is PORTA version and another PORTB version.

May 3, 2011 - I wrote a very simple C program on MPLAB to set all ports to high on a PIC. Is supposed to support W7) This is the code: #include #include. The 16F628 has 7 internal peripherals that make it very useful for different projects. Buy the 16F628A version and code operation will be identical - the 16F628A. The two most important features are that there is 2k of program memory and. And simple schedulers plus simple analysis of arduino millis() code; Find out.

PORTB version works as expected. PORTA version works only in one direction in Proteus but works in both directions in debugger. I guess it is a bug of Proteus PIC16F628A model related to PORTA4. I have made small changes to code. Mine is mikroC PRO PIC Compiler codes. See attached video.

It shows PORTA code working as expected. You can see the PORTA values to the right of the screen. See how the values shift in both directions. There are no bugs in Proteus with regard setting and reading the ports except a meta stability issue that may show itself after the code has been running a long time. I think that the problem could be due to the time it takes between setting portA RA4 and reading it back again. Due to the fact that it is an open collector output the rise times are considerably longer. One way of making it work in Proteus is to look at the properties of the resistors and LED and setting them to digital.

Program

Macro expert 3 1 0 cracker. As well as speeding up the simulation it will avoid this problem.