1
Off Topic / C Programming.
« on: March 23, 2009, 08:58:58 PM »
I've got to program a PIC chip with a 4x4 keypad. I have to make a reverse polish calculator. I wouldn't normally ask this, I don't even know if anyone here knows this stuff, but nobody in today's lab finished. It's a crazy hard lab and our teacher doesn't really teach the stuff well.
I don't expect anybody to write the code for me, I don't even really expect help. Any assistance would be much appreciated.
The assignment: http://www.eece.maine.edu/~eason/ece177/lab07.pdf
The starter code:
I don't expect anybody to write the code for me, I don't even really expect help. Any assistance would be much appreciated.
The assignment: http://www.eece.maine.edu/~eason/ece177/lab07.pdf
The starter code:
Quote
#include <pic.h> // Always include this
#include "lcd.h"
#include "delay.h"
#include "printf.h"
__CONFIG(INTIO&WDTDIS&PWRTDIS&MCLREN&UNPROTECT&DUNPROTECT&BORDIS&IESODIS&FCMDIS&LVPDIS&DEBUGDIS);
signed char getkey(void); // forward declarations
unsigned char mapkey(signed char);
signed int getnum(void);
// Global variables, #defines, and enums here
char operator; // operator returned from "getnum()"
enum {enter=10, backspace, plus, minus, times, divide};
void main(void) { // main program here
signed char getkey(void) {
// This routine will get a key on the keypad and will return the
// key number, or -1 if no key is pressed. Keys are numbered top to
// bottom and left to right and the keypad is mapped as follows
// Output Key
// Bits Number
// 0 | 0 1 2 3
// 1 | 4 5 6 7
// 2 | 8 9 10 11
// 3 | 12 13 14 15
// ------------
// 4 5 6 7
// Input Bits
unsigned char mapkey(signed char key) {
// Return the mapping of the given key according to the following
// Key Number Mapping
// | 0 1 2 3 0 | 1 2 3 +
// | 4 5 6 7 1 | 4 5 6 -
// | 8 9 10 11 2 | 7 8 9 *
// | 12 13 14 15 3 | BS 0 EN / (BS = Backspace)
// ------------ ------------ (EN = ENTER)
signed int getnum(void) {
// Wait for user to enter a number followed by an operator. The
// function return value is the number. The operator is returned
// in the global variable "operator".