// x_your_lab2.c // Name // Date // HARDWARE SETUP: // // PORT C physical connections // PORTC: 7 6 5 4 3 2 1 0 // pwn_en_m --| | | | | | | |--unsued // digit select MSB----| | | | | |----unsued // digit select ------| | | |------unused // digit select LSB--------| |--------unsued //hint: swizzle the pins to make the implementation less awkward #include #include #define TRUE 1 #define FALSE 0 #define LOOP_DELAY 500 //delay in ms for the loop //****************************************************************************** // chk_buttons //Checks the state of the button number passed to it. It shifts in ones till //the button is pushed. Function returns a 1 only once per debounced button //push so a debounce and toggle function can be implemented at the same time. //Adapted to check all buttons from Ganssel's "Guide to Debouncing" //Expects active low pushbuttons on PORTA. Debounce time is determined by //external loop delay times 12. The argument "button" is the pushbutton on //the board S1 (button = 0) through S8 (button = 7) // uint8_t chk_buttons(uint8_t button) { } //chk_buttons //****************************************************************************** //*********************************************************************************** // segment_sum //This function takes a 16-bit binary input value and places the appropriate //equivalent 4 digit BCD segment code in an array for display. //The array is loaded at the exit as: |d3|d2|colon|d1|d0| void segsum(uint16_t sum) { }//segment_sum //*********************************************************************************** //*********************************************************************************** int main() { //configure all PORT A pins as WIREDANDPULL OPC[2:0]=111 //can only pull down, pullup is always on //Set port A as an output. The input value will always //be available regardless. TODO Check this. PORTA.DIR = 0xFF; //main while loop while(1){ _delay_loop_2(LOOP_DELAY); //loop debounce required //check each button and increment the change amount //enable tristate buffer for pushbutton switches //assert Y7 output from decoder to allow switches to be read //check each button and increment as necessary //bound the count //break up the disp_value to 4 parts, put BCD digits in an array segsum(disp_value); //Turn on each digit by incrementing the count to PORTC bits 4-6. //This will turn on digits 0 to 3 in succession. //PORTB bit 7 is held low constantly for this lab. } //while } //main