We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello; I m implementing the 4x4 matrix keypad logic. I m using a logic of columns and rows. 4 lines of port are used as rows and other 4 lines are column. If port 1 is used then p1.0 to p1.3 = rows. P1.4 to p1.7 = columns. I check for the key press making one row low. If I find any column low in particular row then I break the loop and returns the matrix I have made for the key press I check for the key press in if loop. And then I break the if loop and come to ‘returning of matrix element logic’ which is present in the same function. Since I can not come out of ‘if’ using break, so I hav used ‘goto LABEL’, to come to ‘returning of matrix logic’ Is it OK to used goto in microcontroller programming? My code is working.
It's no difference to use goto in embedded or in "normal" programs.
I only think it should be used for multi-level break, i.e. when you need to break out of multiple block levels.
Without seeing your code, it is hard to see if there are any simple code rewrites that would allow you to remove the goto. However, if your goal is to return a key press, then you can have multiple return statements in the function. They represent the ultimate "multiple-break" statement :)
You say: "And then I break the if loop..:".
There are no if loops. If your if statement is inside a for(), while() or switch(), then a break will jump out of the if block too, since the break will jump all the way out of the closest for(), while(), switch() block.