Strange errors related with P16F877A-P16F887 and simulation

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times

Strange errors related with P16F877A-P16F887 and simulation

Post by fotios »

In the product "An introduction to microcontroller programming" and under the directory "Flowcode step-by-step" there is a usefull tutorial "A simple Hi-Fi". I tried it for first time with the default MCU P16F877A, there are some lacks and errors in the Flowchart which i corrected so as the volume number does not flicker and the LCD display is updated continuously. Finally, the project it works perfect in simulation mode. I compiled the project in a P16F877A to see if the project it works in real mode just like in the simulator of Flowcode. There is only one error in the real mode: the value of "volume" on LCD, although it gets and shows the current number from the ADC during power-up, if i turn the potentiometer in other place the value on LCD is not updated. This can be done only if i press the reset (MCLR) button of EB006-v7. Instead, in simulation mode, the value is updated normally.
Because i am novice, i found a very interesting property of P16F877 during the developement of this project. That is, the IOC (interrupt on change) property of the RB4 - RB7 pins of port B which is usefull for connecting 4 push-button switches. If the IOC is enabled, then when a switch change state can cause an interrupt (managed internally by the MCU). Latter, i replaced the P16F877A with a P16F887 (it is suggested from Microchip this, because the 887 is the replacement of 877 that means the 877 it is out of production and, indeed, in the market it is more expensive by 1GBP from 887). Except that it includes an internal oscillator (offering thus the option of two more pins available for I/O). I tried for this time the 887 in the place of 877A, using the external XT oscillator of EB006. In simulation mode it works just fine like the 877A, and when the chip is programmed it presents in real mode, the same error of non updating the value of volume given from the ADC like in the case of 877A. This can be done only if we press the MCLR button like with 877A.
I came accross the data sheet of P16F887 and i found another one very important upgrade. All pins of Port B from RB0 to RB7 of 887 have the IOC property, insteed only the top 4 pins of 877A Port B. That is very good. We can have now, 8 external interrupt sources. I must to notice, that i perceived the usefulness of interrupts during the developement of the project "A simple Hi-Fi". They can help to we reduce significantly the code size needed for a project. As well the usefulness of using Macros. Macros can make a project to presented on the flowchart most tidy, as they can reduce the lot of Decisions needed in other case, which extents the size of flowchart on the screen so as is very difficult to we observe the code development and execution in simulation or ICD mode.
BTW i decided to use now the whole switch board connected in Port B of 887. I did the modiffications needed in code and settings. I don't know nothing from C language, the only that it helps me by some way it is the mathematics that i know in the recognision of some operators etc, and everything i remember from the PL-1 language from my studies - from 1976 to 1980 - in the school of Electric Engineers (i am 51 years old). I have still this book of my school "Basic and PL-1" writen in Greek language - during 1975 - but it is a great help because the C language is simillar.
Back again to the project. After the change of settings for the 887, i modified the macro "Chandet" which call the interrupt when is enabled, by masking all bits of Port B and by adding the extra decisions and calculations. When i finished the flowchart, i tried the project in Flowcode simulator. Here, i had the first error. The IOC interrupt has the same behaviour like with the 877A mcu. The interrupt occurs, only when are pressed the top 4 buttons (RB4 - RB7). The lower buttons (RB0 - RB3) are inactive. For the RB0 pin, because is the external interrupt pin, i can't suppose nothing. For the rest RB1 to RB3? Because i had ready the EB006 board for the test, i programmed the P16F887 with success, and then i tried the project in real mode. To my big surprise, the mcu had programmed correctly! All the switches are working, and the LCD as well indicates the correct number of switch pressed. Except the switch which is connected in RB0, which is inactive. Why this disagreement between simulator and real model? In the Flowcode, i opened the "Properties" box, and then the "Interrupt on:" PORT properties, where i can see that the "Interrupt On Change" is enabled for all pins from RB0 to RB7. But the RB0 is not working in real mode.
Can you give me a reply in my queries please?
Thanks and Regards
Fotios
Best Regards FOTIS ANAGNOSTOU

Post Reply