PIC16F Programming

Thread Starter

Gajyamadake

Joined Oct 9, 2019
310
So what's wrong with the code in #16?
I want to make single function that test each buttons in sequence if switches pressed store it somewhere

Update : AlbertHall you posted link while I was typing. I do not have that much of level. I am far away from keyboard. I am teaching my self by solving thoughts comes in mind
 
Last edited:

Thread Starter

Gajyamadake

Joined Oct 9, 2019
310
That's the point. How do you learn coding by never testing the code you write?
I was testing all the codes on my PC. I know I have to get one development board for embedded programming and It would be very soon in my hand

I thought I should spend some time on reading the microcontroller so I started to read the datasheet of PIC16F877A . I am doing more practice on C programming

I think I am not fully ready to jump on embedded programming I should spend more time to learn basic concept of c programming with reading hardware pic16f877a.

I do not want to set very difficult task for myself, for example I wrote one function to check one switch It was easy for me then I tried to add more switches I had struggle and so How can i interfaced matrix keyboard that's why I am afraid and want to achieve goal with small steps
 
Last edited:

jpanhalt

Joined Jan 18, 2008
11,087
This comment is with reference to two threads, namely the datasheet one and this one. In the datasheet thread, I asked whether you had "tested" the code. I was not referring only to hardware testing. For flashing an LED, simulation will be fine.

Are you testing the code on your computer with simulation or just to see whether it compiles? There can be a world of difference between something that simply compiles and something that works in simulation.
 

atferrari

Joined Jan 6, 2004
4,769
@AlbertHall @atferrari
Assume we have bellow 16 buttons like this each label A B C D E F G H I J K L M N O P

I know the basics of c programming so how to use basic concept to read the all buttons. remember I am not talking about coding. I am asking for logic

It's really hard me to solve the problem I don't have idea whatever I had in mind I have already explained
View attachment 191192View attachment 191193View attachment 191194View attachment 191195
Basically whatever I could say without going into explaining the whole subject in detail, goes in line with what Albert is telling you. Reading 16 buttons separately sounds irrational.
 

Thread Starter

Gajyamadake

Joined Oct 9, 2019
310
Basically whatever I could say without going into explaining the whole subject in detail, goes in line with what Albert is telling you. Reading 16 buttons separately sounds irrational.
I am sorry but I think that's not solution of problem

Let's take simple example only four switches A B C D

test four buttons in sequence if buttons pressed store it somewhere

First pass A C
Second Pass B C D
Third Pass D A B C
Fourth Pass C A D C
Fifth Pass Doesn't press anything
Sixth Pass C C C C
..N Pass ... X X X X

If doesn't make sense I will have to move on another topics
 

danadak

Joined Mar 10, 2018
4,057
I would tackle this as a scanned function, one key at a time, testing its
state and debounce it.

However a brute force method, that would allow any/all keys to be simultaneously
handled would be the following. This is a one chip solution, only used small fraction
of overall chip resources. So all keys or 1 key could be pressed simultaneously and
this approach handles/debounces them all. Depending how you connect the debouncer
output (you select the edge you want to use) you have running in the foreground a code
loop to check the states and act accordingly whatever function you want to occur.

Basically each key is connected to an onchip HW debouncer (for each key). You can take the +, -, either edge
and connect that to a register or other logic, like a D F-F to make the key latching. Or a timer or counter or
whatever.

1573576336354.png

PSOC, compiler and IDE free. Board to use $ 10, $ 4 if you use the bootloader version of the board.

Lots of other resources onchip, like A/D, OpAmps, Comparators, Timers, PWM, COM......


Regards, Dana.
 
Last edited:

MaxHeadRoom

Joined Jul 18, 2013
28,686
See the Nigel Goodwin Tutorials, (Keyboard example), the code is also available out there in C if preferred. But the matrix explanation and the example of what to do if two buttons accidentally pushed.
16 P.B.? Matrix is the way to go.
Max.
 
Top