Ejemplo n.º 1
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	RingBuffer_InitBuffer(&FromHost_Buffer, FromHost_Buffer_Data, sizeof(FromHost_Buffer_Data));

	GlobalInterruptEnable();

	for (;;)
	{
		/* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
		if (!(RingBuffer_IsFull(&FromHost_Buffer)))
		{
			int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

			/* Read bytes from the USB OUT endpoint into the USART transmit buffer */
			if (!(ReceivedByte < 0))
			  RingBuffer_Insert(&FromHost_Buffer, ReceivedByte);
		}

		while (RingBuffer_GetCount(&FromHost_Buffer) > 0)
		{
			static uint8_t EscapePending = 0;
			int16_t HD44780Byte = RingBuffer_Remove(&FromHost_Buffer);

			if (HD44780Byte == COMMAND_ESCAPE)
			{
				if (EscapePending)
				{
					HD44780_WriteData(HD44780Byte);
					EscapePending = 0;
				}
				else
				{
					/* Next received character is the command byte */
					EscapePending = 1;
				}
			}
			else
			{
				if (EscapePending)
				{
					HD44780_WriteCommand(HD44780Byte);
					EscapePending = 0;
				}
				else
				{
					HD44780_WriteData(HD44780Byte);
				}
			}
		}

		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Ejemplo n.º 2
0
void HD44780_GoToPoint(char row, char col)
{
	char DDRAM_address;
	
	if(row<1) row=1;				// first position user-defined as (1,1)
	if(col<=1)col=0;				// but HD44780 defines as (0,0)
	else col=col-1;

	if(row==1) DDRAM_address = 0x80+col;		// 0x80 for set DDRAM address command
	if(row==2) DDRAM_address = 0x80+0x40+col;	// 0x40 for second line DDRAM address

	HD44780_WriteCommand(DDRAM_address);
}
Ejemplo n.º 3
0
void HD44780_Init(void)
{
	//Using initialize by instruction
	//After power on Wait for LCD to Initialize
	delay100MiliSecond();
	HD44780_initPinIO();
	
	HD44780_EN_PIN	 = 0;
    HD44780_RS_PIN	 = 0;
	HD44780_DATA_PORT = 0x30;
	HD44780_Clock();
	delay5MiliSecond();
	
	HD44780_DATA_PORT = 0x30;
	HD44780_Clock();
	delay200MicroSecond();
	
    HD44780_DATA_PORT = 0x30;
	HD44780_Clock();
	delay200MicroSecond();
		
	// FUNCTION SET				| 0  0  1  1  N  F  *  * |
	// BIN_OR_BIT_MASK:			{ 0  0  1  1  1  0  0  0 }
	HD44780_WriteCommand(0x38);	// N = 1; 2 lines, F = 0; 5x8 dots
	delay5MiliSecond();
	// DISPLAY OFF
	HD44780_WriteCommand(0x0C);
	delay5MiliSecond();
	// DISPLAY CLEAR
	HD44780_WriteCommand(0x01);
	delay5MiliSecond();
	// ENTRY MODE SET			| 0  0  0  0  0  1  I/D  S |
	// BIN_OR_BIT_MASK:			{ 0  0  0  0  0  1   1   0 }
	HD44780_WriteCommand(0x06);	// I/D = 1; Increment by 1, S = 0; No shift
	delay5MiliSecond();
	// HOME POSITION
	HD44780_WriteCommand(0x80);
}
Ejemplo n.º 4
0
/** Configures the board hardware and chip peripherals for the application's functionality. */
void SetupHardware(void)
{
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Hardware Initialization */
	USB_Init();

	/* Power up the HD44780 Interface */
	HD44780_Initialize();
	HD44780_WriteCommand(CMD_DISPLAY_ON);
	
	/* Start the flush timer so that overflows occur rapidly to push received bytes to the USB interface */
	TCCR0B = (1 << CS02);
}