/* main.c - 4x4 matrix keypad and LED demo for Dragon12-Plus board.
 * Copyright 2008 Colin D. Bennett <colin@gibibit.com>.
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 */

#include "hc12drivers/keypad.h"
#include "hc12/hcs12.h"

int main(void)
{
	/*** Configure LEDs. ***/
	DDRB = 0xFF;   // Set port B to output for LEDs (PB7:0 are LED anodes).
	DDRJ = 0xFF;   // Set port J to output, so we can enable LEDs w/ PJ1.
	PTJ = 0;       // Pull PJ1 low to enable LEDs.
	DDRP = 0xFF;   // Set port P to output, (to turn off 7-seg display).
	PTP = 0xFF;    // PP3:0 are 7-segment common cathodes: turn them off.

	/*** Configure keypad: PA7:4 input, PA3:0 output. ***/
	keypad_init();

	/*** Main loop. ***/
	while (1)
	{
		/* Read the pressed scan code and display it in binary
		 * on the row of LEDs.  When no key is pressed, -1 is returned, so
		 * all LEDs are lit. */
		PORTB = keypad_read_scancode();
	}
}

