In: Electrical Engineering
#include <windows.h>
HANDLE hComm;
void OpenComm()
{
DCB dcb;
hComm = CreateFile("COM1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if(hComm==INVALID_HANDLE_VALUE) exit(1);
if(!SetupComm(hComm, 4096, 4096)) exit(1);
if(!GetCommState(hComm, &dcb)) exit(1);
dcb.BaudRate = 115200;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = 0;
if(!SetCommState(hComm, &dcb)) exit(1);
}
void CloseComm()
{
CloseHandle(hComm);
}
DWORD WriteComm(char* buf, int len)
{
DWORD nSend;
if(!WriteFile(hComm, buf, len, &nSend, NULL)) exit(1);
return nSend;
}
void WriteCommByte(BYTE b)
{
WriteComm(&b, 1);
}
DWORD ReadComm(char *buf, int len)
{
DWORD nRec;
if(!ReadFile(hComm, buf, len, &nRec, NULL)) exit(1);
return nRec;
}
void main()
{
OpenComm();
// Initialize LCD 16x2
WriteCommByte(0x38); // Used to select 8 bit mode
WriteCommByte(0x0F); // When display On cursor will be on
WriteCommByte(0x01); // Clear the content of display
Sleep(2);
// Program for displaying "TECH" word
WriteCommByte('T'+0x80);
WriteCommByte('E'+0x80);
WriteCommByte('C'+0x80);
WriteCommByte('H'+0x80);
CloseComm();
}
//END