Solusi Programmer AVR K125-R Bluescreen

Downloader/Programmer AVR K125-R menggunakan chip serial sebelum ke chip programmernya. Chip serial ini biasanya tipe PL-2303HX yang drivernya belum support Windows 8-10 jadi jika dipaksakan terkadang mengakibatkan bluescreen PC. Untuk mengatasinya, chip tersebut bisa diganti dengan tipe baru yaitu PL-2303HXD (prolific.com.tw/US/ShowProduct.aspx?p_id=225&pcid=41). Cara lainnya yaitu dengan menggunakan modul USB to TTL dengan menjumper ke K125-R seperti gambar di bawah. Cukup jumper TX, RX, dan GND. Dengan demikian PORT yang digunakan untuk downloader kita memakai PORT modul USB to TTL yang sudah support Windows 8-10.

img_20170211_185750 img_20170211_185757 img_20170211_185727

RTC DS3231 I2C ATMega128

rtc_lib.c

#include <mega128.h>
#include <string.h>
#include <stdlib.h>
#include <delay.h>
#include <twi.h>
#include <math.h>
#include "i2c_lib.h"
#include "rtc_lib.h"

char string_tochar(char char1, char char2)
{
	char char1_num	= char1 - 48;
	char H_byte		= char1_num << 4;
	char all_byte	= H_byte | (char2-48);
	return all_byte; 
}

void RTC_Init(void)
{
	_I2C_Init();                             // Initialize the _I2C module.
	_I2C_Start();                            // Start _I2C communication
	
	_I2C_Write(WriteMode_U8);        // Connect to DS1307 by sending its ID on _I2C Bus
	_I2C_Write(ControlRegAddress_U8);// Select the Ds1307 ControlRegister to configure Ds1307
	
	_I2C_Write(0x00);                        // Write 0x00 to Control register to disable SQW-Out
	
	_I2C_Stop();                             // Stop _I2C communication after initializing DS1307
}

void RTC_SetDateTime(rtc_hex *rtc)
{
	_I2C_Start();                          // Start _I2C communication
	
	_I2C_Write(WriteMode_U8);      // connect to DS1307 by sending its ID on _I2C Bus
	_I2C_Write(SecondRegAddress_U8); // Request sec RAM address at 00H
	
	_I2C_Write(rtc->sec);                    // Write sec from RAM address 00H
	_I2C_Write(rtc->min);                    // Write min from RAM address 01H
	_I2C_Write(rtc->hour&0x3F);                    // Write hour from RAM address 02H
	_I2C_Write(rtc->weekDay);                // Write weekDay on RAM address 03H
	_I2C_Write(rtc->date);                    // Write date on RAM address 04H
	_I2C_Write(rtc->month);                    // Write month on RAM address 05H
	_I2C_Write(rtc->year);                    // Write year on RAM address 06h
	
	_I2C_Stop();                              // Stop _I2C communication after Setting the Date
}

void RTC_GetDateTime(rtc_hex *rtc)
{
	_I2C_Start();                            // Start _I2C communication
	
	_I2C_Write(WriteMode_U8);        // connect to DS1307 by sending its ID on _I2C Bus
	_I2C_Write(SecondRegAddress_U8); // Request Sec RAM address at 00H
	
	//_I2C_Stop();                                // Stop _I2C communication after selecting Sec Register
	
	_I2C_Start();                            // Start _I2C communication
	_I2C_Write(ReadMode_U8);            // connect to DS1307(Read mode) by sending its ID
	
	rtc->sec = _I2C_ReadACK();                // read second and return Positive ACK
	rtc->min = _I2C_ReadACK();                 // read minute and return Positive ACK
	rtc->hour= _I2C_ReadACK();               // read hour and return Negative/No ACK
	rtc->weekDay = _I2C_ReadACK();           // read weekDay and return Positive ACK
	rtc->date= _I2C_ReadACK();              // read Date and return Positive ACK
	rtc->month=_I2C_ReadACK();            // read Month and return Positive ACK
	rtc->year =_I2C_ReadNACK();             // read Year and return Negative/No ACK
	
	_I2C_Stop();                              // Stop _I2C communication after reading the Date
}

rtc_lib.h

#ifndef RTC_LIB_H_
#define RTC_LIB_H_


#define ReadMode_U8   0xD1u  
#define WriteMode_U8  0xD0u  
#define ControlRegAddress_U8 0x0Eu
#define SecondRegAddress_U8 0x00u

typedef struct
{
	unsigned char sec;
	unsigned char min;
	unsigned char hour;
	unsigned char weekDay;
	unsigned char date;
	unsigned char month;
	unsigned char year;
}rtc_hex;

extern void RTC_Init(void);
extern void RTC_SetDateTime(rtc_hex *rtc);
extern void RTC_GetDateTime(rtc_hex *rtc);
extern char string_tochar(char char1, char char2);


#endif /* RTC_LIB_H_ */

Level Shifter 5V dari/ke 3.3V Menggunakan LM339 IC Comparator

level_shifter

USART Interrupt Atmel Studio

// USART0 Receiver interrupt service routine
ISR(USART0_RX_vect)
{
	char status,data;
	status=UCSR0A;
	data=UDR0;
	if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
	{
		rx_buffer0[rx_wr_index0++]=data;
		#if RX_BUFFER_SIZE0 == 256
		// special case for receiver buffer size=256
		if (++rx_counter0 == 0) rx_buffer_overflow0=1;
		#else
		if (rx_wr_index0 == RX_BUFFER_SIZE0) rx_wr_index0=0;
		if (++rx_counter0 == RX_BUFFER_SIZE0)
		{
			rx_counter0=0;
			rx_buffer_overflow0=1;
		}
		#endif
	}
}

Open & Save File C#

void SaveFileToolStripMenuItemClick(object sender, EventArgs e)
{
	saveFileDialog1.ShowDialog();						
}

void SaveFileDialog1FileOk(object sender, CancelEventArgs e)
{
	string filePath = saveFileDialog1.FileName;
	string[] dataToSave = new string[] {txtCompanyName.Text, 																										
										txtPlant.Text,																												
										txtModel.Text,																													
										cbShift.SelectedIndex.ToString(),	
										cbShiftMode.SelectedIndex.ToString(),
										dtpShiftTime1.Value.Hour.ToString() + ":" + dtpShiftTime1.Value.Minute.ToString() + ":" +
										dtpShiftTime2.Value.Hour.ToString() + ":" + dtpShiftTime2.Value.Minute.ToString() + ":" +
										dtpShiftTime3.Value.Hour.ToString() + ":" + dtpShiftTime3.Value.Minute.ToString(), 												
										txtLineIDA.Text,																												
										cbModeA.SelectedIndex.ToString(),																								
										dtpIntervalA.Value.Hour.ToString() + ":" + dtpIntervalA.Value.Minute.ToString() + ":" + dtpIntervalA.Value.Second.ToString(), 	
										nudCounterA.Value.ToString(),																									
										nudExpectedA.Value.ToString(),																									
										txtLineIDB.Text,																													
										cbModeB.SelectedIndex.ToString(),																								
										dtpIntervalB.Value.Hour.ToString() + ":" + dtpIntervalB.Value.Minute.ToString() + ":" + dtpIntervalB.Value.Second.ToString(), 	
										nudCounterB.Value.ToString(),																									
										nudExpectedB.Value.ToString()};
	try
	{
		System.IO.File.WriteAllLines(filePath,dataToSave);	
	}
	catch(Exception ex)
	{
		MessageBox.Show(ex.ToString());
	}
}

void OpenFileDialog1FileOk(object sender, CancelEventArgs e)
{
	string filePath = openFileDialog1.FileName;
	try
	{
		string[] dataToOpen = System.IO.File.ReadAllLines(filePath);
		//------------------------------------------------------------------------------
		txtCompanyName.Text 		= dataToOpen[0];//1
		txtPlant.Text				= dataToOpen[1];//2
		txtModel.Text				= dataToOpen[2];//3
		
		cbShift.SelectedIndex		= (int)Convert.ToInt32(dataToOpen[3]);//4
		cbShiftMode.SelectedIndex	= (int)Convert.ToInt32(dataToOpen[4]);//5
		
		string buffShiftTime		= dataToOpen[5];//6
		string[] splitShiftTime 	= buffShiftTime.Split(':');
		
		dtpShiftTime1.Value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,((int)Convert.ToInt32(splitShiftTime[0])),((int)Convert.ToInt32(splitShiftTime[1])),0);
		dtpShiftTime2.Value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,((int)Convert.ToInt32(splitShiftTime[2])),((int)Convert.ToInt32(splitShiftTime[3])),0);
		dtpShiftTime3.Value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,((int)Convert.ToInt32(splitShiftTime[4])),((int)Convert.ToInt32(splitShiftTime[5])),0);
		//------------------------------------------------------------------------------				
		txtLineIDA.Text				= dataToOpen[6];//7
		
		cbModeA.SelectedIndex		= (int)Convert.ToInt32(dataToOpen[7]);//8
		
		string buffInterval			= dataToOpen[8];//9
		string[] splitInterval 		= buffInterval.Split(':');
		dtpIntervalA.Value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,((int)Convert.ToInt32(splitInterval[0])),((int)Convert.ToInt32(splitInterval[1])),((int)Convert.ToInt32(splitInterval[2])));
		
		nudCounterA.Value			= (int)Convert.ToInt32(dataToOpen[9]);//10
		nudExpectedA.Value			= (int)Convert.ToInt32(dataToOpen[10]);//11
		//------------------------------------------------------------------------------				
		txtLineIDB.Text				= dataToOpen[11];//12
		
		cbModeB.SelectedIndex		= (int)Convert.ToInt32(dataToOpen[12]);//13
		
		buffInterval				= dataToOpen[13];//14
		splitInterval 				= buffInterval.Split(':');
		dtpIntervalB.Value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,((int)Convert.ToInt32(splitInterval[0])),((int)Convert.ToInt32(splitInterval[1])),((int)Convert.ToInt32(splitInterval[2])));
		
		nudCounterB.Value			= (int)Convert.ToInt32(dataToOpen[14]);//15
		nudExpectedB.Value			= (int)Convert.ToInt32(dataToOpen[15]);//16
		//------------------------------------------------------------------------------
	}
	catch(Exception ex)
	{
		MessageBox.Show(ex.ToString());
	}
}

void LoadFileToolStripMenuItemClick(object sender, EventArgs e)
{
	openFileDialog1.ShowDialog();	
}

UDP Server & Client C#

private void SendMessage( string data)
{
	Byte[] message = Encoding.ASCII.GetBytes(data);
	epSenderToClient = new IPEndPoint(IPAddress.Parse(ipAddress.Text), 8899);
	serverSocket.BeginSendTo(message, 0, message.Length, SocketFlags.None, epSenderToClient, 
					new AsyncCallback(OnSend), epSenderToClient);
	txtMessageWindow2.AppendText("Me>>" + data + Environment.NewLine);
	txtMessageWindow2.ScrollToCaret();
	
	txtTextMessage.Clear();
	txtTextMessage.Focus();
}

private void udpBridgeMessage(string data)
{
	Byte[] message = Encoding.ASCII.GetBytes(data);
	
	txtMessageWindow2.AppendText("Me>>" + data + Environment.NewLine);
	txtMessageWindow2.ScrollToCaret();
	
	txtTextMessage.Clear();
	txtTextMessage.Focus();
}

void MainFormFormClosing(object sender, FormClosingEventArgs e)
{
	btnConnect.Text = "Connect";
	_terminated = true;	
	if(statUdpClientConnect)
	{
		serverSocket.Close();
	}
	
	if(statStartServer)
	{
		myServer.Stop();
	}
}

Socket serverSocket;
byte[] byteData = new byte[1024];

void createConnection()
{
	try
	{
		CheckForIllegalCrossThreadCalls = false;
	
		//We are using UDP sockets
		serverSocket = new Socket(AddressFamily.InterNetwork, 
			SocketType.Dgram, ProtocolType.Udp);

		//Assign the any IP of the machine and listen on port number 1000
		IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, Convert.ToInt32(ipPort.Text));

		//Bind this address to the server
		serverSocket.Bind(ipEndPoint);
		
		IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
		//The epSender identifies the incoming clients
		EndPoint epSender = (EndPoint) ipeSender;

		//Start receiving data
		serverSocket.BeginReceiveFrom (byteData, 0, byteData.Length, 
			SocketFlags.None, ref epSender, new AsyncCallback(OnReceive), epSender);                
	}
	catch (Exception ex) 
	{ 
		MessageBox.Show(ex.ToString());
	}
}

bool statUdpClientConnect = false;
void BtnConnectClick(object sender, EventArgs e)
{
	if(btnConnect.Text == "Connect")
	{	
		
		btnConnect.Text = "Disconnect";
		_terminated = false;
		dispEnable(true);
		createConnection();
	}
	else if(btnConnect.Text == "Disconnect")
	{
		try
		{
			btnConnect.Text = "Connect";
			btnPublishBridgeData.Text = "Bridge";
			txtPublishBridgeDataIP.Enabled = true;
			_terminated = true;
			dispEnable(false);
			statUdpClientConnect =  false;
			serverSocket.Close();
			if(statStartServer)
			{
				myServer.Stop();
				btnPublishStartServer.Text = "Start Server";
				publishServerItemDisable(true);
			}
		}
		catch(Exception ex)
		{
			MessageBox.Show(ex.ToString());
		}
	}					
}

bool _terminated = false;
EndPoint epSenderToClient;
private void OnReceive(IAsyncResult ar)
{
	try
	{	
		if(_terminated)
		{
			return;
		}
		IPEndPoint ipeSender 	= new IPEndPoint(IPAddress.Any, 0);
		EndPoint epSender 		= (EndPoint)ipeSender;
		EndPoint epSenderBridge	= new IPEndPoint(IPAddress.Parse(txtPublishBridgeDataIP.Text), Convert.ToInt32(ipPort.Text));
		
		serverSocket.EndReceiveFrom (ar, ref epSender);
		
		string IPtext = epSender.ToString();
		string[] justGetIP = IPtext.Split(':');
		if(justGetIP[0] == ipAddress.Text)
		{
			//Transform the array of bytes received from the user into an
			//intelligent form of object Data
			object[] para = {System.Text.Encoding.ASCII.GetString(byteData)};
			this.Invoke(new delUpdateHistory(UpdateHistory), para);
				
			byte [] message = byteData;
			
			if(btnPublishBridgeData.Text == "Break")
			{
				//Send the name of the users in the chat room
				serverSocket.BeginSendTo (message, 0, message.Length, SocketFlags.None, epSenderBridge, 
						new AsyncCallback(OnSend), epSenderBridge); 
			}
	   }
	   
	   Array.Clear(byteData,0,byteData.Length);
	   serverSocket.BeginReceiveFrom (byteData, 0, byteData.Length, SocketFlags.None, ref epSender,
				new AsyncCallback(OnReceive), epSender);            
	}
	catch (Exception ex)
	{ 
		MessageBox.Show(ex.ToString());
	}
}

public void OnSend(IAsyncResult ar)
{
	try
	{                
		serverSocket.EndSend(ar);
	}
	catch (Exception ex)
	{ 
		MessageBox.Show(ex.ToString());
	}
}

int prevIntShift = 1;
//---delegate and subroutine to update the TextBox control---
public delegate void delUpdateHistory(string str);
public void UpdateHistory(string message)
{
	if(message.Length > 25)
	{
		txtMessageWindow.Text = txtMessageWindow.Text + Environment.NewLine + message;
		txtMessageWindow.SelectionStart = txtMessageWindow.TextLength;
		
		if(!cktxtMessageWindowScroll.Checked)
		{
			txtMessageWindow.ScrollToCaret();
		}
		txtMessageWindow.Refresh();
		
		string[] dev_string = message.Split(';');
		if((dev_string.Length == 25)&&(!ckEdit.Checked))
		{
			//-------------------------------------------------------
			string[] array_receive = dev_string[1].Split('=');
			if(array_receive[0] == "shift")
			{
				try
				{
					int intShift = Convert.ToInt32(array_receive[1]);
					if(((intShift >= 1) && (intShift <= 3)) && (intShift != prevIntShift))
					{
						exportTableAToCSV();
						exportTableBToCSV();
						
						//---------------clear table A-----------------
						dataGridViewA.Rows.Clear();
	
						GraphPane myPane1 = chartA1.GraphPane;
						myPane1.CurveList.Clear();
						chartA1.Refresh();
						chartA1.AxisChange();   
						chartA1.Invalidate();	
			
			
						GraphPane myPane2 = chartA2.GraphPane;
						myPane2.CurveList.Clear();
						chartA2.Refresh();
						chartA2.AxisChange();   
						chartA2.Invalidate();
						//---------------clear table B-----------------
						dataGridViewB.Rows.Clear();
	
						GraphPane myPane3 = chartB1.GraphPane;
						myPane3.CurveList.Clear();
						chartB1.Refresh();
						chartB1.AxisChange();   
						chartB1.Invalidate();	
			
			
						GraphPane myPane4 = chartB2.GraphPane;
						myPane4.CurveList.Clear();
						chartB2.Refresh();
						chartB2.AxisChange();   
						chartB2.Invalidate();
					}
					prevIntShift = intShift;
					cbShift.SelectedIndex = intShift - 1;
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.ToString());	
				}
			}
			//-------------------------------------------------------
			array_receive = dev_string[2].Split('=');
			if(array_receive[0] == "current_time")
			{
				try
				{
					string[] splitTimeDate = array_receive[1].Split(',');
					string[] splitTime = splitTimeDate[0].Split(':');
					string[] splitDate = splitTimeDate[1].Split(':');
					
					int timeHour 	= Convert.ToInt32(splitTime[0]);
					int timeMinute = Convert.ToInt32(splitTime[1]);
					int timeSecond = Convert.ToInt32(splitTime[2]);
					
					int dateDay		= Convert.ToInt32(splitDate[1]);
					int dateMonth	= Convert.ToInt32(splitDate[2]);
					int dateYear	= 2000 + Convert.ToInt32(splitDate[3]);
					
					dtpTimeNDate.Value = new DateTime(dateYear,dateMonth,dateDay,timeHour,timeMinute,timeSecond);
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.ToString());	
				}
			}
			//-------------------------------------------------------
			array_receive = dev_string[3].Split('=');
			if(array_receive[0] == "company")
			{
				txtCompanyName.Text = array_receive[1];
			}
			//-------------------------------------------------------
			array_receive = dev_string[4].Split('=');
			if(array_receive[0] == "model")
			{
				txtModel.Text = array_receive[1];
			}
			//-------------------------------------------------------
			array_receive = dev_string[5].Split('=');
			if(array_receive[0] == "plant")
			{
				txtPlant.Text = array_receive[1];
			}
			//-------------------------------------------------------
			array_receive = dev_string[6].Split('=');
			if(array_receive[0] == "lineIDA")
			{
				txtLineIDA.Text = array_receive[1];
			}
			//-------------------------------------------------------
			array_receive = dev_string[7].Split('=');
			if(array_receive[0] == "modeA")
			{
				int intModeA = Convert.ToInt32(array_receive[1]);
				cbModeA.SelectedIndex = intModeA;
			}
			//-------------------------------------------------------
			array_receive = dev_string[8].Split('=');
			if(array_receive[0] == "tim_intervalA")
			{
				try
				{
					string[] splitTime = array_receive[1].Split(':');
					
					int timeHour   = Convert.ToInt32(splitTime[0]);
					int timeMinute = Convert.ToInt32(splitTime[1]);
					int timeSecond = Convert.ToInt32(splitTime[2]);
					
					dtpIntervalA.Value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,timeHour,timeMinute,timeSecond);
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.ToString());	
				}		
			}
			//-------------------------------------------------------
			array_receive = dev_string[9].Split('=');
			if(array_receive[0] == "time_targetA")
			{
				
			}
			//-------------------------------------------------------
			array_receive = dev_string[10].Split('=');
			if(array_receive[0] == "target_expectedA")
			{
				int intTargetExpectedA = Convert.ToInt32(array_receive[1]);
				nudExpectedA.Value = intTargetExpectedA;
			}
			//-------------------------------------------------------
			array_receive = dev_string[11].Split('=');
			if(array_receive[0] == "counterA")
			{
				int intCounterA = Convert.ToInt32(array_receive[1]);
				nudCounterA.Value = intCounterA;
			}
			//-------------------------------------------------------
			array_receive = dev_string[12].Split('=');
			if(array_receive[0] == "differenceA")
			{
				
			}
			//-------------------------------------------------------
			array_receive = dev_string[13].Split('=');
			if(array_receive[0] == "lineIDB")
			{
				txtLineIDB.Text = array_receive[1];
			}
			//-------------------------------------------------------
			array_receive = dev_string[14].Split('=');
			if(array_receive[0] == "modeB")
			{
				int intModeB = Convert.ToInt32(array_receive[1]);
				cbModeB.SelectedIndex = intModeB;
			}
			//-------------------------------------------------------
			array_receive = dev_string[15].Split('=');
			if(array_receive[0] == "tim_intervalB")
			{
				try
				{
					string[] splitTime = array_receive[1].Split(':');
					
					int timeHour   = Convert.ToInt32(splitTime[0]);
					int timeMinute = Convert.ToInt32(splitTime[1]);
					int timeSecond = Convert.ToInt32(splitTime[2]);
					
					dtpIntervalB.Value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,timeHour,timeMinute,timeSecond);
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.ToString());	
				}		
			}
			//-------------------------------------------------------
			array_receive = dev_string[16].Split('=');
			if(array_receive[0] == "time_targetA")
			{
				
			}
			//-------------------------------------------------------
			array_receive = dev_string[17].Split('=');
			if(array_receive[0] == "target_expectedB")
			{
				int intTargetExpectedB = Convert.ToInt32(array_receive[1]);
				nudExpectedB.Value = intTargetExpectedB;
			}
			//-------------------------------------------------------
			array_receive = dev_string[18].Split('=');
			if(array_receive[0] == "counterB")
			{
				int intCounterB = Convert.ToInt32(array_receive[1]);
				nudCounterB.Value = intCounterB;
			}
			//-------------------------------------------------------
			array_receive = dev_string[17].Split('=');
			if(array_receive[0] == "differenceA")
			{
				
			}
			//-------------------------------------------------------
			array_receive = dev_string[20].Split('=');
			if(array_receive[0] == "shift_mode")
			{
				int intShiftMode = Convert.ToInt32(array_receive[1]);
				cbShiftMode.SelectedIndex = intShiftMode;	
			}    
			//-------------------------------------------------------
			array_receive = dev_string[21].Split('=');
			if(array_receive[0] == "shift_time1")
			{
				try
				{
					string[] splitTime = array_receive[1].Split(':');
					
					int timeHour   = Convert.ToInt32(splitTime[0]);
					int timeMinute = Convert.ToInt32(splitTime[1]);
					
					dtpShiftTime1.Value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,timeHour,timeMinute,0);
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.ToString());	
				}		
			}
			//-------------------------------------------------------
			array_receive = dev_string[22].Split('=');
			if(array_receive[0] == "shift_time2")
			{
				try
				{
					string[] splitTime = array_receive[1].Split(':');
					
					int timeHour   = Convert.ToInt32(splitTime[0]);
					int timeMinute = Convert.ToInt32(splitTime[1]);
					
					dtpShiftTime2.Value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,timeHour,timeMinute,0);
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.ToString());	
				}		
			}
			//-------------------------------------------------------
			array_receive = dev_string[23].Split('=');
			if(array_receive[0] == "shift_time3")
			{
				try
				{
					string[] splitTime = array_receive[1].Split(':');
					
					int timeHour   = Convert.ToInt32(splitTime[0]);
					int timeMinute = Convert.ToInt32(splitTime[1]);
					
					dtpShiftTime3.Value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,timeHour,timeMinute,0);
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.ToString());	
				}		
			}
			//-------------------------------------------------------
			array_receive = dev_string[0].Split('=');
			if(array_receive[0] == "stat_update_wifi")
			{
				try
				{
					int intStatUpdate = Convert.ToInt32(array_receive[1]);
					switch(intStatUpdate)
					{
						case 0 :
							{
								tmLightUpdate.Enabled = true;	
							}
							break;	
						case 1 :
							{
								saveDataGridViewA();
								tmLightAUp.Enabled = true;	
							}
							break;
						case 2 :
							{
								deleteLastRowA();
								tmLightADown.Enabled = true;
							}
							break;
						case 3 :
							{
								saveDataGridViewB();
								tmLightBUp.Enabled = true;
							}
							break;
						case 4 :
							{
								deleteLastRowB();
								tmLightBDown.Enabled = true;
							}
							break;
					}
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.ToString());
				}
			}
			//-----------------------------------------------------------------------
		}
	}
	else if(message.Length > 1)
	{
		stringCommandValueRespond = message;
		txtMessageWindow2.Text = txtMessageWindow2.Text + Environment.NewLine + "Device>>" + message;
		txtMessageWindow2.SelectionStart = txtMessageWindow2.TextLength;
		txtMessageWindow2.ScrollToCaret();
		txtMessageWindow2.Refresh();	               	
	}
}

Run as Administrator C#

app.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
	<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
		<security>
			<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
				<!--
					The presence of the "requestedExecutionLevel" node will disable
					file and registry virtualization on Vista.
					
					Use the "level" attribute to specify the User Account Control level:
						asInvoker            = Never prompt for elevation
						requireAdministrator = Always prompt for elevation
						highestAvailable     = Prompt for elevation when started by administrator,
						                       but do not prompt for administrator password when started by
						                       standard user.
				-->
				<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
				<!--<requestedExecutionLevel  level="asInvoker" />
				
				<requestedExecutionLevel  level="requireAdministrator"/>
				-->
			</requestedPrivileges>
		</security>
	</trustInfo>
</assembly>

USART Timeout AVR

char getchar(void)
{
	unsigned int counter1 = 0,
	counter2 = 0,
	counter3 = 0;
	char data = 0;
    stat_timeout = 0;
	while(rx_counter0==0)
	{
		counter1++; 
		if (counter1>1000)
		{
			counter1 = 0;
			counter2++;
			if (counter2>1000)
			{
				counter2 = 0;
				counter3++;
				if (counter3>5)
				{
					stat_timeout = 1;
					break;
				}
			}
		}
	};
	if (stat_timeout == 0)
	{
		data=rx_buffer0[rx_rd_index0++];
		#if RX_BUFFER_SIZE0 != 256
		if (rx_rd_index0 == RX_BUFFER_SIZE0) rx_rd_index0=0;
		#endif
		#asm("cli")
		--rx_counter0;
		#asm("sei")   
	}
	return data;
}

SL032 UART Mifare Reader / Writer module

unsigned char get_rfid_data()
{
    int i;
	char check_sum = 0;
	
	putchar(0xBA);
	putchar(0x02);
	putchar(0x01);
	putchar(0xB9);
	putchar(0x00);
	
	data_receive[0] = getchar(); 
    if(stat_timeout == 1)
    {
        lcd_clear();
        lcd_gotoxy(0,0);
        lcd_putsf("USART0:timeout"); 
        delay_ms(1000);
    }
	if(data_receive[0] == 0xBD)
	{
		data_receive[1] = getchar(); 
        if(stat_timeout == 1)
        {
            lcd_clear();
            lcd_gotoxy(0,0);
            lcd_putsf("USART0:timeout"); 
            delay_ms(1000);
        }
        
		if(data_receive[1] == 0x08)
		{
			for(i=2;i<10;i++)
			{
				data_receive[i] = getchar(); 
                if(stat_timeout == 1)
                {
                    lcd_clear();
                    lcd_gotoxy(0,0);
                    lcd_putsf("USART0:timeout");  
                    delay_ms(1000);
                }
			}
			check_sum = 0;
			for(i=0;i<10;i++)
			{
				check_sum ^= data_receive[i];
			}
			if((check_sum == 0x00)&&(data_receive[3] == 0x00))
			{
				return 1;
			}
			else
			{        
                lcd_clear();
                lcd_gotoxy(0,0);
                lcd_putsf("RFID:wrong checksum");     
                delay_ms(1000);
				return 0;
			}
		}
		else
		{
			return 0;
		}
	}
	else
	{
		return 0;
	}
}

Keypad 3×4 Microcontroller AVR

keypad_lib.c

#include <stdlib.h>
#include <mega128.h>
#include <delay.h>
#include <stdlib.h>
#include "keypad_lib.h"
#include "IO_lib.h"

void buzzer_beep()
{
    sound_buzzer(1);
    delay_ms(100);
    sound_buzzer(0);
}

void buzzer_delay(int buff_delay)
{
    sound_buzzer(1);
    delay_ms(buff_delay);
    sound_buzzer(0);     
    delay_ms(buff_delay);
}

void buzzer_beep_delay(int buff_delay)
{
    buzzer_beep();    
    if(buff_delay>100)
    { 
        delay_ms(buff_delay-100); 
    }
}

void keypad_bounchdelay()
{
	char buffer_read_keypad = read_keypad();
	if(buffer_read_keypad != '$')
	{   
        sound_buzzer(1);
		do
		{
			buffer_read_keypad = read_keypad();
		}while(buffer_read_keypad != '$');       
	    sound_buzzer(0);
	}
}

char read_keypad()
{	
	DDR_keypad = 0b00001111;
	/* 1 2 3
	   4 5 6
	   7 8 9
	   * 0 #
	*/
	
	PORT_keypad = 0b11111110;
	delay_us(10);
	//scan baris 1
	if(PIN_keypad == 0b11101110)
	{         
		return ('1');	
	}
	else if(PIN_keypad == 0b11011110)
	{                
		return ('2');
	}
	else if(PIN_keypad == 0b10111110)
	{                 
		return ('3');
	}
	
	//scan baris 2	
	PORT_keypad = 0b11111101;
	delay_us(10);
	if(PIN_keypad == 0b11101101)
	{                 
		return ('4');
	}
	else if(PIN_keypad == 0b11011101)
	{                 
		return ('5');
	}
	else if(PIN_keypad == 0b10111101)
	{                 
		return ('6');
	}
	
	//scan baris 3
	PORT_keypad = 0b11111011;
	delay_us(10);
	if(PIN_keypad == 0b11101011)
	{                 
		return ('7');
	}
	else if(PIN_keypad == 0b11011011)
	{                 
		return ('8');
	}
	else if(PIN_keypad == 0b10111011)
	{                 
		return ('9');
	}
	
	//scan baris 4
	PORT_keypad = 0b11110111;
	delay_us(10);
	if(PIN_keypad == 0b11100111)
	{                 
		return ('*');
	}
	else if(PIN_keypad == 0b11010111)
	{                 
		return ('0');
	}
	else if(PIN_keypad == 0b10110111)
	{                 
		return ('#');
	}
	return ('$');
}

char keypad_string_mode(unsigned char lcd_x, unsigned char lcd_y )
{	
	char buffer_keypad = '$';
	char string_buffer = '$';
	unsigned int counter_string_mode = 0;
	while(1)
	{
		buffer_keypad = read_keypad();
		switch(buffer_keypad)
		{
			case '1':
					string_buffer = '1';
					counter_string_mode = 0;
					while (buffer_keypad != '$')
					{
						buffer_keypad = read_keypad();
						if(buffer_keypad == '$') break;
						else if (buffer_keypad == '1')
						{
							switch(counter_string_mode)
							{
								case 0: string_buffer = '1';
								break;
								case 1: string_buffer = ' ';
								break;
								case 2: string_buffer = '-';
								break;
								case 3: string_buffer = '@';
								break;
								case 4: string_buffer = ':';
								break;
								case 5: string_buffer = '(';
								break;
								case 6: string_buffer = ')';
								break;
							}
							lcd_gotoxy(lcd_x,lcd_y);
							lcd_putchar(string_buffer);
							buzzer_beep_delay(500);
							counter_string_mode++;
							if(counter_string_mode > 6) counter_string_mode = 0;
						}
						else
						{
							break;						
						}
					}
					return string_buffer;
				break;
			case '2':
					string_buffer = '2';
					counter_string_mode = 0;
					while (buffer_keypad != '$')
					{
						buffer_keypad = read_keypad();
						if(buffer_keypad == '$') break;
						else if (buffer_keypad == '2')
						{
							switch(counter_string_mode)
							{
								case 0: string_buffer = '2';
									break;
								case 1: string_buffer = 'a';
									break;
								case 2: string_buffer = 'b';
									break;
								case 3: string_buffer = 'c';
									break;
								case 4: string_buffer = 'A';
									break;
								case 5: string_buffer = 'B';
									break;
								case 6: string_buffer = 'C';
									break;					
							}
							lcd_gotoxy(lcd_x,lcd_y);
							lcd_putchar(string_buffer);
							buzzer_beep_delay(500);
							counter_string_mode++;
							if(counter_string_mode > 6) counter_string_mode = 0;
						}
						else
						{
							break;
						}
					} 
					return string_buffer;
				break;
			case '3':
					string_buffer = '3';
					counter_string_mode = 0;
					while (buffer_keypad != '$')
					{
						buffer_keypad = read_keypad();
						if(buffer_keypad == '$') break;
						else if (buffer_keypad == '3')
						{
							switch(counter_string_mode)
							{
								case 0: string_buffer = '3';
								break;
								case 1: string_buffer = 'd';
								break;
								case 2: string_buffer = 'e';
								break;
								case 3: string_buffer = 'f';
								break;
								case 4: string_buffer = 'D';
								break;
								case 5: string_buffer = 'E';
								break;
								case 6: string_buffer = 'F';
								break;
							}
							lcd_gotoxy(lcd_x,lcd_y);
							lcd_putchar(string_buffer);
							buzzer_beep_delay(500);
							counter_string_mode++;
							if(counter_string_mode > 6) counter_string_mode = 0;
						}
						else
						{
							break;
						}
					}
					return string_buffer;
				break;
			case '4':
					string_buffer = '4';
					counter_string_mode = 0;
					while (buffer_keypad != '$')
					{
						buffer_keypad = read_keypad();
						if(buffer_keypad == '$') break;
						else if (buffer_keypad == '4')
						{
							switch(counter_string_mode)
							{
								case 0: string_buffer = '4';
								break;
								case 1: string_buffer = 'g';
								break;
								case 2: string_buffer = 'h';
								break;
								case 3: string_buffer = 'i';
								break;
								case 4: string_buffer = 'G';
								break;
								case 5: string_buffer = 'H';
								break;
								case 6: string_buffer = 'I';
								break;
							}
							lcd_gotoxy(lcd_x,lcd_y);
							lcd_putchar(string_buffer);
							buzzer_beep_delay(500);
							counter_string_mode++;
							if(counter_string_mode > 6) counter_string_mode = 0;
						}
						else
						{
							break;
						}
					}
					return string_buffer;
				break;
			case '5':
					string_buffer = '5';
					counter_string_mode = 0;
					while (buffer_keypad != '$')
					{
						buffer_keypad = read_keypad();
						if(buffer_keypad == '$') break;
						else if (buffer_keypad == '5')
						{
							switch(counter_string_mode)
							{
								case 0: string_buffer = '5';
								break;
								case 1: string_buffer = 'j';
								break;
								case 2: string_buffer = 'k';
								break;
								case 3: string_buffer = 'l';
								break;
								case 4: string_buffer = 'J';
								break;
								case 5: string_buffer = 'K';
								break;
								case 6: string_buffer = 'L';
								break;
							}
							lcd_gotoxy(lcd_x,lcd_y);
							lcd_putchar(string_buffer);
							buzzer_beep_delay(500);
							counter_string_mode++;
							if(counter_string_mode > 6) counter_string_mode = 0;
						}
						else
						{
							break;
						}
					}
					return string_buffer;
				break;
			case '6':
					string_buffer = '6';
					counter_string_mode = 0;
					while (buffer_keypad != '$')
					{
						buffer_keypad = read_keypad();
						if(buffer_keypad == '$') break;
						else if (buffer_keypad == '6')
						{
							switch(counter_string_mode)
							{
								case 0: string_buffer = '6';
								break;
								case 1: string_buffer = 'm';
								break;
								case 2: string_buffer = 'n';
								break;
								case 3: string_buffer = 'o';
								break;
								case 4: string_buffer = 'M';
								break;
								case 5: string_buffer = 'N';
								break;
								case 6: string_buffer = 'O';
								break;
							}
							lcd_gotoxy(lcd_x,lcd_y);
							lcd_putchar(string_buffer);
							buzzer_beep_delay(500);
							counter_string_mode++;
							if(counter_string_mode > 6) counter_string_mode = 0;
						}
						else
						{
							break;
						}
					}
					return string_buffer;
				break;
			case '7':
					string_buffer = '7';
					counter_string_mode = 0;
					while (buffer_keypad != '$')
					{
						buffer_keypad = read_keypad();
						if(buffer_keypad == '$') break;
						else if (buffer_keypad == '7')
						{
							switch(counter_string_mode)
							{
								case 0: string_buffer = '7';
								break;
								case 1: string_buffer = 'p';
								break;
								case 2: string_buffer = 'q';
								break;
								case 3: string_buffer = 'r';
								break;
								case 4: string_buffer = 's';
								break;
								case 5: string_buffer = 'P';
								break;
								case 6: string_buffer = 'Q';
								break;
								case 7: string_buffer = 'R';
								break;
								case 8: string_buffer = 'S';
								break;
							}
							lcd_gotoxy(lcd_x,lcd_y);
							lcd_putchar(string_buffer);
							buzzer_beep_delay(500);
							counter_string_mode++;
							if(counter_string_mode > 8) counter_string_mode = 0;
						}
						else
						{
							break;
						}
					}
					return string_buffer;
				break;
			case '8':
					string_buffer = '8';
					counter_string_mode = 0;
					while (buffer_keypad != '$')
					{
						buffer_keypad = read_keypad();
						if(buffer_keypad == '$') break;
						else if (buffer_keypad == '8')
						{
							switch(counter_string_mode)
							{
								case 0: string_buffer = '8';
								break;
								case 1: string_buffer = 't';
								break;
								case 2: string_buffer = 'u';
								break;
								case 3: string_buffer = 'v';
								break;
								case 4: string_buffer = 'T';
								break;
								case 5: string_buffer = 'U';
								break;
								case 6: string_buffer = 'V';
								break;
							}
							lcd_gotoxy(lcd_x,lcd_y);
							lcd_putchar(string_buffer);
							buzzer_beep_delay(500);
							counter_string_mode++;
							if(counter_string_mode > 6) counter_string_mode = 0;
						}
						else
						{
							break;
						}
					}
					return string_buffer;
				break;
			case '9':
					string_buffer = '9';
					counter_string_mode = 0;
					while (buffer_keypad != '$')
					{
						buffer_keypad = read_keypad();
						if(buffer_keypad == '$') break;
						else if (buffer_keypad == '9')
						{
							switch(counter_string_mode)
							{
								case 0: string_buffer = '9';
								break;
								case 1: string_buffer = 'w';
								break;
								case 2: string_buffer = 'x';
								break;
								case 3: string_buffer = 'y';
								break;
								case 4: string_buffer = 'z';
								break;
								case 5: string_buffer = 'W';
								break;
								case 6: string_buffer = 'X';
								break;
								case 7: string_buffer = 'Y';
								break;
								case 8: string_buffer = 'Z';
								break;
							}
							lcd_gotoxy(lcd_x,lcd_y);
							lcd_putchar(string_buffer);
							buzzer_beep_delay(500);
							counter_string_mode++;
							if(counter_string_mode > 8) counter_string_mode = 0;
						}
						else
						{
							break;
						}
					}
					return string_buffer;
				break;
			case '*': 
                {
				    buzzer_beep();
					return '*';  
                }
				break;
			case '0': 
                {
                    buzzer_beep();
					return '0';  
                }
				break;
			case '#': 
                {
                    buzzer_beep();
					return '#';   
                }
				break;			
		}
	}
}

char keypad_increment_mode()
{
	char buffer_keypad = '$';
	buffer_keypad = read_keypad();			
	if ((buffer_keypad == '*')||
	    (buffer_keypad == '#')||
		(buffer_keypad == '0')||
		(buffer_keypad == '8'))
    {
	    return buffer_keypad;
    }
    else
    {
        return '$';
    }						 
}

unsigned char check_leap_year(unsigned int year)
{
	if		(year%400	== 0)return LEAP_YEAR_YES;
	else if (year%100	== 0)return LEAP_YEAR_NO;
	else if (year%4		== 0)return LEAP_YEAR_YES;
	else					 return LEAP_YEAR_NO;
}

unsigned char check_day_of_month(unsigned int month, unsigned int year)
{
	if(month == 2)
	{
		if(check_leap_year(year) == LEAP_YEAR_YES) 
			return 29;
		else
			return 28;  		
	}
	else if((month == 1)||
			(month == 3)||
			(month == 5)||
			(month == 7)||
			(month == 8)||
			(month == 10)||
			(month == 12))
	{
		return 31;				
	}
	else if((month == 4)||
			(month == 6)||
			(month == 9)||
			(month == 11))
	{
		return 30;				
	}
	return 0;
}

keypad_lib.h

#ifndef KEYPAD_LIB_H_
#define KEYPAD_LIB_H_

#include <mega128.h>

#define PORT_keypad PORTB
#define PIN_keypad PINB
#define DDR_keypad DDRB

#define LEAP_YEAR_NO	0
#define LEAP_YEAR_YES	1

void buzzer_beep();
void buzzer_beep_delay(int buff_delay);
void buzzer_delay(int buff_delay);
void keypad_bounchdelay();
char read_keypad();
char keypad_string_mode(unsigned char lcd_x, unsigned char lcd_y );
char keypad_increment_mode();
unsigned char check_leap_year(unsigned int year);
unsigned char check_day_of_month(unsigned int month, unsigned int year);

#endif /* KEYPAD_LIB_H_ */