I have 3 questions to the code below which is pretty messed up (newby).
the program should pull a random number between 1-6 when i push a button and show it on an LCD (button and LCD are set up)
1. how do i include the switch correctly
2. how do i set up a random number counter
3. how do read the number when i push the button and link the random no. to the LCD equivalent.
Any help appreciated.
Thanks in advance,
T
the program should pull a random number between 1-6 when i push a button and show it on an LCD (button and LCD are set up)
1. how do i include the switch correctly
2. how do i set up a random number counter
3. how do read the number when i push the button and link the random no. to the LCD equivalent.
Any help appreciated.
Code:
#define BUTTON RA4 #define HIGH 0 // Button is a pull down #define LOW 1 // Button is a pull down #define Frequency 4000000 #define InitDlay 12 #define LCDTEST 0b01111111; // Test LCD #define LCD1 0b00000110; // Bin 1 #define LCD2 0b01011011; // Bin 2 #define LCD3 0b01001111; // Bin 3 #define LCD4 0b01100110; // Bin 4 #define LCD5 0b01101101; // Bin 5 #define LCD6 0b01111100; // Bin 6 typedef unsigned char uint8_t; void main (void) { int RESULT; int dlay; uint8_t i; // intitialize chip TRISA = 0x1F; // Port A all inputs TRISB = 0xFF; // Port B all output // Main task loop while (1) { button_state = BUTTON; // get current button state while(BUTTON == HIGH) // wait while button isn't pressed { if ((button_state == LOW) && (last_button_state != HIGH)) { (((InitDlay-1)*256)*7)/(Frequency/4); // debounce button switch (RESULT) { CASE 1: PORTB = LCD1; break; CASE 2: PORTB = LCD2; break; CASE 3: PORTB = LCD3; break; CASE 4: PORTB = LCD4; break; CASE 5: PORTB = LCD5; break; CASE 6: PORTB = LCD6; break; default: PORTB = LCDTEST; } } } } return; }
Thanks in advance,
T
Comment