Need help in C, Programming for Z8

Thread Starter

Nguyen204

Joined Nov 19, 2014
2
Hey, I am working on a school lab. Where I have to program prototypes.

void main(void);
unsigned int pushed_button(void);
unsigned int released_button(void);
void button_pushed(void);
void mydelay(unsigned int);


I am given this and I have to use the call function. Not sure where to go as I have no programming background. I've tried searching through the forum for more information, but came up with nothing. any thing will help as I am want to learn and understand what is happening.

thanks.
 

Papabravo

Joined Feb 24, 2006
22,082
I don't know what you expect us to do. A schematic of the hardware might help. Take the function mydelay(5). What does the 5 represent? milliseconds seconds, minutes what?
How is button_pushed() with no argument and no return value useful?
 

Thread Starter

Nguyen204

Joined Nov 19, 2014
2
Sorry, didn't think it required schematic
http://www.zilog.com/appnotes_downl...WdVkyOXlaUzlrWlhaMGIyOXNjeTkxYlRBeE5URXVjR1Jt

I am trying to have a 2ms delay, to wait for the bouncing effect to run its course.
The purpose of this assignment is to count each time the push button is pressed and display the number of presses on the leds, in binary. So I want to debounce the pushbutton switch before registering a count. My program will call the button_pushed() function in order to detect button pushes.

Then I am provided with flow charts, that my code should be based off of.
 

Attachments

Papabravo

Joined Feb 24, 2006
22,082
The schematic would be useful in case you need help on the details of initialization and reading the bits from the port pins.

So think of your program as implementing a sampled data system. The samples are 2 milliseconds apart. In order to detect a push or a release you need to have some number of identical samples. So you could use a byte to keep track of the last 8 samples. If the switch is open you record a 1, and if the switch is closed you record a zero. Let's say we want three consecutive 0's to define a push, and three consecutive 1's to define a release.

To maintain the samples you would take the byte shift it left by one position and ADD or OR the new sample into the least significant bit.
So a push would look like 0b1111 1000, and a release would look like 0b000 0111.

There are many alternative ways to do it but this one has proved very flexible.
 
Top