LED Matrix 16×32 di Arduino

Applikasi LED Matrix di arduino bisa menggunakan library yang sudah ada di internet seperti DMD dan Timer-One seperti dijelaskan pada link berikut.
boarduino.web.id/2016/03/menampilkan-suhu-pada-p10-led-matrix.html
pccontrol.wordpress.com/2016/04/30/pengetahuan-dasar-pemrograman-modul-leddot-matrik-display-dmd-p10-dengan-arduino/
Untuk library yang terbaru, bisa menggunakan library DMD2.
Akan tetapi jika terjadi error dan text tidak muncul, mungkin ini bisa terjadi karena LED Matrix yang digunakan mempunyai mode invers dan tipe latch yang berbeda. Untuk mengeceknya, bisa dibedakan antara signal dari controller aslinya dengan menggunakan logic analyzer. Berikut gambar signal setelah libary DMD2 diedit mengikuti bentuk signal controller LED Matrix bawaannya.

Dalam signal tersebut dikirim 32 data (32 kolom led) dalam 4 kali (AB = 00, 01, 10, 11). Dalam sekali kirim data, dikirim frame data untuk 4 baris sekaligus(4×4 = 16 baris).
Maka editlah beberapa kode pada library DMD sebagai berikut.
1.

inline void setBrightness(byte level) { this->brightness = level; };

ganti menjadi

inline void setBrightness(byte level) { this->brightness = ~level; };

2.

void SoftDMD::writeSPIData(volatile uint8_t *rows[4], const int rowsize)
{
  /* Write out 4 interleaved rows of data using software GPIO rather than SPI. */
  volatile port_reg_t *port_clk = (volatile port_reg_t *)portOutputRegister(digitalPinToPort(pin_clk));
  port_reg_t mask_clk = digitalPinToBitMask(pin_clk);
  volatile port_reg_t *port_r_data = (volatile port_reg_t *) portOutputRegister(digitalPinToPort(pin_r_data));
  port_reg_t mask_r_data = digitalPinToBitMask(pin_r_data);

  for(int i = 0; i < rowsize; i++) {
    softSPITransfer(*(rows[3]++), port_r_data, mask_r_data, port_clk, mask_clk);
    softSPITransfer(*(rows[2]++), port_r_data, mask_r_data, port_clk, mask_clk);
    softSPITransfer(*(rows[1]++), port_r_data, mask_r_data, port_clk, mask_clk);
    softSPITransfer(*(rows[0]++), port_r_data, mask_r_data, port_clk, mask_clk);
  }
}

diganti menjadi

void SoftDMD::writeSPIData(volatile uint8_t *rows[4], const int rowsize)
{
  /* Write out 4 interleaved rows of data using software GPIO rather than SPI. */
  volatile port_reg_t *port_clk = (volatile port_reg_t *)portOutputRegister(digitalPinToPort(pin_clk));
  port_reg_t mask_clk = digitalPinToBitMask(pin_clk);
  volatile port_reg_t *port_r_data = (volatile port_reg_t *) portOutputRegister(digitalPinToPort(pin_r_data));
  port_reg_t mask_r_data = digitalPinToBitMask(pin_r_data);

  for(int i = 0; i < rowsize; i++) {
    softSPITransfer(~(*(rows[3]++)), port_r_data, mask_r_data, port_clk, mask_clk);
    softSPITransfer(~(*(rows[2]++)), port_r_data, mask_r_data, port_clk, mask_clk);
    softSPITransfer(~(*(rows[1]++)), port_r_data, mask_r_data, port_clk, mask_clk);
    softSPITransfer(~(*(rows[0]++)), port_r_data, mask_r_data, port_clk, mask_clk);
  }
}

3.

void BaseDMD::scanDisplay()
{
  if(pin_other_cs >= 0 && digitalRead(pin_other_cs) != HIGH)
    return;
  // Rows are send out in 4 blocks of 4 (interleaved), across all panels

  int rowsize = unified_width_bytes();

  volatile uint8_t *rows[4] = { // Scanning out 4 interleaved rows
    bitmap + (scan_row + 0) * rowsize,
    bitmap + (scan_row + 4) * rowsize,
    bitmap + (scan_row + 8) * rowsize,
    bitmap + (scan_row + 12) * rowsize,
  };

  writeSPIData(rows, rowsize);

  digitalWrite(pin_noe, LOW);
  digitalWrite(pin_sck, HIGH); // Latch DMD shift register output
  digitalWrite(pin_sck, LOW); // (Deliberately left as digitalWrite to ensure decent latching time)

  // Digital outputs A, B are a 2-bit selector output, set from the scan_row variable (loops over 0-3),
  // that determines which set of interleaved rows we are outputting during this pass.
  // BA 0 (00) = 1,5,9,13
  // BA 1 (01) = 2,6,10,14
  // BA 2 (10) = 3,7,11,15
  // BA 3 (11) = 4,8,12,16
  digitalWrite(pin_a, scan_row & 0x01);
  digitalWrite(pin_b, scan_row & 0x02);
  scan_row = (scan_row + 1) % 4;

  // Output enable pin is either fixed on, or PWMed for a variable brightness display
  if(brightness == 255)
    digitalWrite(pin_noe, HIGH);
  else
    analogWrite(pin_noe, brightness);
}

diganti menjadi

void BaseDMD::scanDisplay()
{
  if(pin_other_cs >= 0 && digitalRead(pin_other_cs) != HIGH)
    return;
  // Rows are send out in 4 blocks of 4 (interleaved), across all panels

  int rowsize = unified_width_bytes();

  volatile uint8_t *rows[4] = { // Scanning out 4 interleaved rows
    bitmap + (scan_row + 0) * rowsize,
    bitmap + (scan_row + 4) * rowsize,
    bitmap + (scan_row + 8) * rowsize,
    bitmap + (scan_row + 12) * rowsize,
  };
	
  digitalWrite(pin_noe, LOW);
  writeSPIData(rows, rowsize);

  // Digital outputs A, B are a 2-bit selector output, set from the scan_row variable (loops over 0-3),
  // that determines which set of interleaved rows we are outputting during this pass.
  // BA 0 (00) = 1,5,9,13
  // BA 1 (01) = 2,6,10,14
  // BA 2 (10) = 3,7,11,15
  // BA 3 (11) = 4,8,12,16
  digitalWrite(pin_a, scan_row & 0x01);
  digitalWrite(pin_b, scan_row & 0x02);
  scan_row = (scan_row + 1) % 4;

  digitalWrite(pin_sck, HIGH); // Latch DMD shift register output
  digitalWrite(pin_sck, LOW); // (Deliberately left as digitalWrite to ensure decent latching time)

  // Output enable pin is either fixed on, or PWMed for a variable brightness display
  if(brightness == 255)
    digitalWrite(pin_noe, HIGH);
  else
    analogWrite(pin_noe, brightness);
}

Wear Levelling EEPROM

Ref: atmel.com/images/doc2526.pdf
Jika kita mempunyai sistem yang secara berkala write data EEPROM, maka hal itu akan mengurangi lifespan dari EERPOM itu sendiri, mengingat bahwa EEPROM mempunyai kapasitas 100.000 erase/write cycle. Dengan menggunakan circular buffer (O-buffer), hal ini memungkinkan untuk meningkatkan lifespan dari penggunaan EEPROM. Caranya adalah dengan mendistribusikan media penyimpanan pada cell EEPROM lainnya. Jika kita memakai 2 cell yang digunakan sebagai parameter yang akan kita simpan, maka kita mempunyai kemungkian lifespan 200.000 erase/write. Akan tetapi, untuk mengetahui dimana letak terakhir dari EEPROM yang kita simpan, maka kita memerlukan sebuah pointer. Untuk mencover posisi pointer, setelah power off, maka kita memerlukan O-buffer kedua.

Setiap kali kita akan memperbarui parameter EEPROM, kita geser pointer ke cell selanjutnya. Dengan demikian penulisan EEPROM akan terdistribusi. Dan untuk pembacaan kita baca dimana terakhir pointer itu berada. Salah satu kendalanya, ialah ketika setelah power off, maka pointer akan kembali ke-reset. Untuk itu kita perlu mencari suatu algoritma yang akan mengecek dimana pointer terkhir dengan menggunakan data dari status buffer. Algoritmanya yaitu dengan mengecek nilai selisih antara nilai status buffer ke-n dikurangi status buffer ke-n+1 harus mempunyai selisih > 1. Dengan menggunakan algoritma ini dan sedikit modifikasi kita sudah bisa mendeteksi dimana pointer terakhir berada. Akan tetapi perlu diingat, penggunaan metode ini akan memerlukan penggunaan memory EEPROM yang boros. Salah satu cara untuk mengurangi pemborosan ini adalah menggunakan metode ini untuk multiple parameter yang akan menyimpan data secara bersamaan dan beroperasi secara paralel.
Berikut gambaran sederhana dari algoritma tersebut yang terdiri dari beberapa prosedur: findCurrentEepromAddr() yang mengidentifikasi dimana letak pointer setelah reset device. EeReadBuffer() membaca parameter dari buffer. EeWriteBuffer() menyimpan parameter pada Parameter Buffer.

Berikut contoh sourcecodenya:

#define SIZE_EEPROM_LEVELLING 64                                        //This algorithm to make long usage of eeprom

eeprom unsigned char status_memory_shift[SIZE_EEPROM_LEVELLING];     //wear levelling
eeprom unsigned char parameter_memory_shift[SIZE_EEPROM_LEVELLING];  //http://www.atmel.com/images/doc2526.pdf

unsigned char pointer_memory_shift;                                  //This algorithm to make long usage of eeprom
unsigned char counter_pointer_shift;                                 //wear levelling  http://www.atmel.com/images/doc2526.pdf
.
.
.
.
.
.
//-------------Wear Levelling EEPROM shift------------------
void eeprom_init_shift()//inisialisasi di awal program
{
    int i = 0;
    for(i=0;i<SIZE_EEPROM_LEVELLING;i++)
    {
        status_memory_shift[i]    = 0;
        parameter_memory_shift[i] = 1;
    }
}

void find_eeprom_pointer_shift()//mencari letak pointer terakhir, dipakai di awal program
{
    int i = 0;             
    int next_addr = 1;
    for(i=0;i<SIZE_EEPROM_LEVELLING;i++)
    {                
        next_addr = i+1;
        if(next_addr >= SIZE_EEPROM_LEVELLING)
        {
            next_addr = 0;
        }
        if((abs((int)status_memory_shift[next_addr]-(int)status_memory_shift[i])>1)||(((int)status_memory_shift[i] == 1)&&((int)status_memory_shift[next_addr] == 0))||(((int)status_memory_shift[i] == 0)&&((int)status_memory_shift[next_addr] == 0)))
        {         
            pointer_memory_shift = i;
            counter_pointer_shift = status_memory_shift[i];
            i = (int)SIZE_EEPROM_LEVELLING;
        }
    }    
}

void write_eeprom_levelling_shift(unsigned char value)//contoh: unsigned char NilaiVar = 47;
{                                                      //write_eeprom_levelling_shift(NilaiVar);
    int i;
    unsigned char prev_counter_pointer_shift = counter_pointer_shift;
    pointer_memory_shift++;  
    counter_pointer_shift++;
    if(pointer_memory_shift >= SIZE_EEPROM_LEVELLING)      
    {
        pointer_memory_shift = 0;    
    }       
    if((prev_counter_pointer_shift == 255)&& (counter_pointer_shift == 0)) 
    {
        for(i=0;i<SIZE_EEPROM_LEVELLING;i++)
        {
            status_memory_shift[i] = 0;    
        } 
        pointer_memory_shift = 0;       
    }           
    status_memory_shift[pointer_memory_shift] = counter_pointer_shift;
    parameter_memory_shift[pointer_memory_shift] = value;      
}

unsigned char read_eeprom_levelling_shift()        //contoh: unsigned char NilaiVar;
{                                                //NilaiVar = read_eeprom_levelling_shift(); 
    return(parameter_memory_shift[pointer_memory_shift]);
}

Interface MCP 41XXX Digital Potentiometer dengan Atmel Studio

Features
• 256 taps for each potentiometer
• Potentiometer values for 10 kΩ, 50 kΩ and
100 kΩ
• Single and dual versions
• SPI™ serial interface (mode 0,0 and 1,1)
• ±1 LSB max INL & DNL
• Low power CMOS technology
• 1 µA maximum supply current in static operation
• Multiple devices can be daisy-chained together
(MCP42XXX only)
• Shutdown feature open circuits of all resistors for
maximum power savings
• Hardware shutdown pin available on MCP42XXX
only
• Single supply operation (2.7V – 5.5V)
• Industrial temperature range: -40°C to +85°C
• Extended temperature range: -40°C to +125°C

digpot1

digpot2

digpot3

digpot4

digpot5

digpot6

 
Berikut contoh kode menggunakan Atmel Studio.

#ifndef F_CPU
#define F_CPU 11059200UL // or whatever may be your frequency
#endif
#include <avr/io.h>
#include <util/delay.h>

#define SCK				PINA0
#define SI				PINA1
#define CS				PINA2

#define COMMAND_WRITE	1
#define P0				0
#define P1				1
#define C0				4
#define C1				5

void IO_init();
void write_data(uint8_t command, uint8_t data);

int main(void)
{
	IO_init();
	/* Replace with your application code */
	uint8_t counter = 0;
    while (1) 
    {
		write_data(1,counter++);
		_delay_ms(10);
    }
}

void IO_init()
{
	DDRA |= ((1 <<PINA0)|(1 <<PINA1)|(1 <<PINA2));
	PORTA |= (1<<CS);
	_delay_ms(1000);
}

void write_data(uint8_t command, uint8_t data)
{
	int i = 0;
	uint8_t command_to_send = 0;
	command_to_send |= ((command<<C0)|(command<<P0));  		
	//Low CS
	PORTA &= ~(1<<CS);
	_delay_us(10);
	//send command
	for(i=7;i>=0;i--)
	{
		if (((command_to_send>>i)&1)==1)
		{
			PORTA |= (1<<SI);
		}
		else
		{
			PORTA &= ~(1<<SI);
		}
		_delay_us(10);		
		PORTA |= (1<<SCK);
		_delay_us(20);
		PORTA &= ~(1<<SCK);
		_delay_us(10);
	}
	//send data
	for(i=7;i>=0;i--)
	{
		if (((data>>i)&1)==1)
		{
			PORTA |= (1<<SI);
		}
		else
		{
			PORTA &= ~(1<<SI);
		}
		_delay_us(10);
		PORTA |= (1<<SCK);
		_delay_us(20);
		PORTA &= ~(1<<SCK);
		_delay_us(10);
	}
	PORTA &= ~(1<<SI);//Low SI
	//High CS
	PORTA |= (1<<CS);
}

Linux Command & Setting

*)Auto mount usb flash drive

sudo apt-get install usbmount

sudo apt-get install ntfs-3g

sudo nano /etc/usbmount/usbmount.conf

-change it to :

FILESYSTEMS="vfat ntfs fuseblk ext2 ext3 ext4 hfsplus"

-We change it to:

FS_MOUNTOPTIONS="-fstype=ntfs-3g,nls=utf8,umask=007,gid=46
-fstype=fuseblk,nls=utf8,umask=007,gid=46 -fstype=vfat,gid=1000,uid=1000,umask=007"

-Create the file usbmount.rules in /etc/udev/rules.d/ with

sudo nano /etc/udev/rules.d/usbmount.rules
KERNEL=="sd*", DRIVERS=="sbp2",         ACTION=="add",  PROGRAM="/bin/systemd-escape -p --template=usbmount@.service $env{DEVNAME}", ENV{SYSTEMD_WANTS}+="%c"
KERNEL=="sd*", SUBSYSTEMS=="usb",       ACTION=="add",  PROGRAM="/bin/systemd-escape -p --template=usbmount@.service $env{DEVNAME}", ENV{SYSTEMD_WANTS}+="%c"
KERNEL=="ub*", SUBSYSTEMS=="usb",       ACTION=="add",  PROGRAM="/bin/systemd-escape -p --template=usbmount@.service $env{DEVNAME}", ENV{SYSTEMD_WANTS}+="%c"
KERNEL=="sd*",                          ACTION=="remove",       RUN+="/usr/share/usbmount/usbmount remove"
KERNEL=="ub*",                          ACTION=="remove",       RUN+="/usr/share/usbmount/usbmount remove"

-Create the file usbmount@.service in /etc/systemd/system/ with

sudo nano /etc/systemd/system/usbmount@.service
[Unit]
BindTo=%i.device
After=%i.device

[Service]
Type=oneshot
TimeoutStartSec=0
Environment=DEVNAME=%I
ExecStart=/usr/share/usbmount/usbmount add
RemainAfterExit=yes

-Now reboot and check with

cat /etc/mtab

-By Default they are mountet to /media/usbstick0

*)Setting password wifi
-command

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

-dalam bracket network tambahkan

	ssid="NAMA_WIFI"
	psk="YOUR_PASSWORD"
	key_mgmt=WPA-PSK

*)Menghilangkan cursor mouse
-instal unclutter command

 sudo apt-get install unclutter

-edit di

/etc/xdg/lxsession/LXDE-pi/autostart

-tambahkan

@unclutter -idle 5 -root

*)Ganti static IP
-command

sudo nano /etc/dhcpcd.conf

-tambahkan

SSID ANDON_3
inform 10.10.100.101

SSID ANDON_3
inform 10.10.100.101

SSID ANDON_3
inform 10.10.100.101

*)Setup Static IP
Reference:
thepihut.com/blogs/raspberry-pi-tutorials/16683276-how-to-setup-a-static-ip-address-on-your-raspberry-pi
linuxtechie.wordpress.com/2014/08/23/setting-up-raspberry-pi-with-wifi-and-a-static-ip-on-a-hidden-ssid/
-command

sudo nano /etc/network/interfaces

– replace

iface wlan0 inet dhcp 

with

iface wlan0 inet static

-add

address [your chosen IP address]
netmask [your netmask]
network [your destination]
broadcast [your broadcast range]
gateway [your gateway]

*)Cek IP address
-command

ip addr show

*) Making wlan0 Rasp pi automatically on every reboot
– command

sudo nano /etc/network/interfaces

– add

auto wlan0

*) Turning off wlan0 power management to prevent automatically disabled wlan0
– command

crontab -e

– pilih 2
– add

@reboot sudo iwconfig wlan0 power off 

*)2 – Disabling the blank screen forever
-command

sudo nano /etc/lightdm/lightdm.conf

-Add the following lines to the [SeatDefaults] section:

	# don't sleep the screen
	xserver-command=X -s 0 -dpms
	

*)Hiding MenuBar Raspberry
– command

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

– Comment baris dengan //

//@lxpanel --profile LXDE-pi

– Ctrl+X -> y -> Enter
– command

sudo nano .config/lxsession/LXDE-pi/autostart

– Comment baris dengan //

//@lxpanel --profile LXDE-pi

– Ctrl+X -> y -> Enter

*) Install remote desktop
-command

sudo apt-get install xrdp

*)Install samba
-command

sudo apt-get install samba samba-common-bin

-command

sudo nano /etc/samba/smb.conf

-lalu edit:

workgroup = WORKGROUP
wins support = yes

-add to bottom:

[PiShare]
 comment=Raspberry Pi Share
 path=/home/pi/dist
 browseable=Yes
 writeable=Yes
 only guest=no
 create mask=0777
 directory mask=0777
 public=no

-command

sudo smbpasswd -a pi

*)Splashscreen
-command

sudo apt-get install fbi

-Copy your custom splash image into: /etc/ and name it splash.png.

sudo cp source dest

-Create A Script
-command

sudo nano

-ketikan:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          asplashscreen
# Required-Start:
# Required-Stop:
# Should-Start:
# Default-Start:     S
# Default-Stop:
# Short-Description: Show custom splashscreen
# Description:       Show custom splashscreen
### END INIT INFO

do_start () {

    /usr/bin/fbi -T 1 -noverbose -a /etc/splash.png
    exit 0
}

case "$1" in
  start|"")
    do_start
    ;;
  restart|reload|force-reload)
    echo "Error: argument '$1' not supported" >&2
    exit 3
    ;;
  stop)
    # No-op
    ;;
  status)
    exit 0
    ;;
  *)
    echo "Usage: asplashscreen [start|stop]" >&2
    exit 3
    ;;
esac

:

-Exit and save the file as: /etc/init.d/asplashscreen
-command

sudo chmod a+x /etc/init.d/asplashscreen

-command

sudo insserv /etc/init.d/asplashscreen

-command

sudo reboot

*)Install new font
-Copy a new TrueType fonts (*.ttf) font file in the directory /usr/share/fonts (for all users)

sudo cp source dest

*) Autostart program java on raspberry
– Copy file .jar ke folder home/pi raspberry
– Buka lxterminal / cmd
– Ketik command

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

– Tambahkan di akhir dgn

@java -jar /home/pi/namaprogram.jar

– Ctrl+X -> y -> Enter
– Ketik command

sudo nano .config/lxsession/LXDE-pi/autostart

– Tambahkan di akhir dgn

@java -jar /home/pi/namaprogram.jar

– Ctrl+X -> y -> Enter

*) Fullscreen program java on raspberry
-Hiding title bar pada program java
-tambahkan class ini

public void setFullScreen() {
    dispose();
    setUndecorated(true);
    setVisible(true);
    setExtendedState(MAXIMIZED_BOTH);
}

-panggil di main program

*)Setting up HDMI output when video output isn’t what you want
reference: raspberrypi.org/forums/viewtopic.php?t=5851
-buka config.txt, bisa dengan cara console pada raspi atau dibuka pada PC
-jika dengan console

sudo nano /boot/config.txt

-masukan kode berikut

hdmi_mode=16
hdmi_drive=2
hdmi_group=1
force_hdmi_hotplug=1
hdmi_ignore_edid=0xa5000080

-nilai hdmi_mode berdasarkan ketentuan di bawah ini
CEA (hdmi_group = 1)

HDMI_CEA_VGA = 1
HDMI_CEA_480p60 = 2
HDMI_CEA_480p60H = 3
HDMI_CEA_720p60 = 4
HDMI_CEA_1080i60 = 5
HDMI_CEA_480i60 = 6
HDMI_CEA_480i60H = 7
HDMI_CEA_240p60 = 8
HDMI_CEA_240p60H = 9
HDMI_CEA_480i60_4x = 10
HDMI_CEA_480i60_4xH = 11
HDMI_CEA_240p60_4x = 12
HDMI_CEA_240p60_4xH = 13
HDMI_CEA_480p60_2x = 14
HDMI_CEA_480p60_2xH = 15
HDMI_CEA_1080p60 = 16
HDMI_CEA_576p50 = 17
HDMI_CEA_576p50H = 18
HDMI_CEA_720p50 = 19
HDMI_CEA_1080i50 = 20
HDMI_CEA_576i50 = 21
HDMI_CEA_576i50H = 22
HDMI_CEA_288p50 = 23
HDMI_CEA_288p50H = 24
HDMI_CEA_576i50_4x = 25
HDMI_CEA_576i50_4xH = 26
HDMI_CEA_288p50_4x = 27
HDMI_CEA_288p50_4xH = 28
HDMI_CEA_576p50_2x = 29
HDMI_CEA_576p50_2xH = 30
HDMI_CEA_1080p50 = 31
HDMI_CEA_1080p24 = 32
HDMI_CEA_1080p25 = 33
HDMI_CEA_1080p30 = 34
HDMI_CEA_480p60_4x = 35
HDMI_CEA_480p60_4xH = 36
HDMI_CEA_576p50_4x = 37
HDMI_CEA_576p50_4xH = 38
HDMI_CEA_1080i50_rb = 39
HDMI_CEA_1080i100 = 40
HDMI_CEA_720p100 = 41
HDMI_CEA_576p100 = 42
HDMI_CEA_576p100H = 43
HDMI_CEA_576i100 = 44
HDMI_CEA_576i100H = 45
HDMI_CEA_1080i120 = 46
HDMI_CEA_720p120 = 47
HDMI_CEA_480p120 = 48
HDMI_CEA_480p120H = 49
HDMI_CEA_480i120 = 50
HDMI_CEA_480i120H = 51
HDMI_CEA_576p200 = 52
HDMI_CEA_576p200H = 53
HDMI_CEA_576i200 = 54
HDMI_CEA_576i200H = 55
HDMI_CEA_480p240 = 56
HDMI_CEA_480p240H = 57
HDMI_CEA_480i240 = 58
HDMI_CEA_480i240H = 59
HDMI_CEA_720p24 = 60
HDMI_CEA_720p25 = 61
HDMI_CEA_720p30 = 62
HDMI_CEA_1080p120 = 63
HDMI_CEA_1080p100 = 64

DMT (hdmi_group = 2)

HDMI_DMT_640x350_85 = 0x1, /**<640×350 */
HDMI_DMT_640x400_85 = 0x2, /**<640×400 */
HDMI_DMT_IBM_VGA_85 = 0x3, /**<720×400 */
HDMI_DMT_VGA_60 = 0x4, /**<640×480 (60Hz is same as VGA in CEA above) */
HDMI_DMT_VGA_72 = 0x5
HDMI_DMT_VGA_75 = 0x6
HDMI_DMT_VGA_85 = 0x7
HDMI_DMT_SVGA_56 = 0x8, /**<800×600 */
HDMI_DMT_SVGA_60 = 0x9
HDMI_DMT_SVGA_72 = 0xA
HDMI_DMT_SVGA_75 = 0xB
HDMI_DMT_SVGA_85 = 0xC
HDMI_DMT_SVGA_120 = 0xD
HDMI_DMT_848x480_60 = 0xE, /**<848×480 */
HDMI_DMT_XGA_43 = 0xF, /**<1024×768 – interlaced, DO NOT USE */
HDMI_DMT_XGA_60 = 0x10, /**<1024×768 */
HDMI_DMT_XGA_70 = 0x11
HDMI_DMT_XGA_75 = 0x12
HDMI_DMT_XGA_85 = 0x13
HDMI_DMT_XGA_120 = 0x14
HDMI_DMT_XGAP_75 = 0x15, /**<1152×864 */
HDMI_DMT_WXGA_RB = 0x16, /**<1280×768 reduced blanking */
HDMI_DMT_WXGA_60 = 0x17
HDMI_DMT_WXGA_75 = 0x18
HDMI_DMT_WXGA_85 = 0x19
HDMI_DMT_WXGA_120 = 0x1A, /**<120Hz with reduced blanking */
HDMI_DMT_1280x800_RB = 0x1B, /**<1280×800 reduced blanking */
HDMI_DMT_1280x800_60 = 0x1C
HDMI_DMT_1280x800_75 = 0x1D
HDMI_DMT_1280x800_85 = 0x1E
HDMI_DMT_1280x800_120 = 0x1F, /** reduced blanking */
HDMI_DMT_1280x960_60 = 0x20, /**<1280×960 */
HDMI_DMT_1280x960_85 = 0x21
HDMI_DMT_1280x960_120 = 0x22, /** reduced blanking */
HDMI_DMT_SXGA_60 = 0x23, /**<1280×1024 */
HDMI_DMT_SXGA_75 = 0x24
HDMI_DMT_SXGA_85 = 0x25
HDMI_DMT_SXGA_120 = 0x26, /** reduced blanking */
HDMI_DMT_1360x768_60 = 0x27, /**<1360×768 */
HDMI_DMT_1360x768_120 = 0x28, /**<120 Hz with reduced blanking */
HDMI_DMT_SXGAP_RB = 0x29, /**<1400×1050 reduced blanking */
HDMI_DMT_SXGAP_60 = 0x2A
HDMI_DMT_SXGAP_75 = 0x2B
HDMI_DMT_SXGAP_85 = 0x2C
HDMI_DMT_SXGAP_120 = 0x2D, /** reduced blanking */
HDMI_DMT_1440x900_RB = 0x2E, /**<1440×900 reduced blanking */
HDMI_DMT_1440x900_60 = 0x2F
HDMI_DMT_1440x900_75 = 0x30
HDMI_DMT_1440x900_85 = 0x31
HDMI_DMT_1440x900_120 = 0x32, /** reduced blanking */
HDMI_DMT_UXGA_60 = 0x33, /**<1600×1200 60Hz */
HDMI_DMT_UXGA_65 = 0x34
HDMI_DMT_UXGA_70 = 0x35
HDMI_DMT_UXGA_75 = 0x36
HDMI_DMT_UXGA_85 = 0x37
HDMI_DMT_UXGA_120 = 0x38, /** reduced blanking */
HDMI_DMT_SWXGAP_RB = 0x39, /**<1680×1050 reduced blanking */
HDMI_DMT_SWXGAP_60 = 0x3A, /**<1680×1050 60Hz */
HDMI_DMT_SWXGAP_75 = 0x3B
HDMI_DMT_SWXGAP_85 = 0x3C
HDMI_DMT_SWXGAP_120 = 0x3D, /** reduced blanking */
HDMI_DMT_1792x1344_60 = 0x3E, /**<1792×1344 60Hz */
HDMI_DMT_1792x1344_75 = 0x3F, /**<1792×1344 75Hz */
HDMI_DMT_1792x1344_120 = 0x40, /** reduced blanking */
HDMI_DMT_1856x1392_60 = 0x41, /**<1856×1392 60Hz */
HDMI_DMT_1856x1392_75 = 0x42, /**<1856×1392 75Hz */
HDMI_DMT_1856x1392_120 = 0x43, /** reduced blanking */
HDMI_DMT_WUXGA_RB = 0x44, /**<1920×1200 reduced blanking */
HDMI_DMT_WUXGA_60 = 0x45, /**<1920×1200 60Hz */
HDMI_DMT_WUXGA_75 = 0x46, /**<1920×1200 75Hz */
HDMI_DMT_WUXGA_85 = 0x47, /**<1920×1200 85Hz */
HDMI_DMT_WUXGA_120 = 0x48, /** reduced blanking */
HDMI_DMT_1920x1440_60 = 0x49, /**<1920×1440 60Hz */
HDMI_DMT_1920x1440_75 = 0x4A, /**<1920×1440 75Hz */
HDMI_DMT_1920x1440_120 = 0x4B, /** reduced blanking */
HDMI_DMT_2560x1600_RB = 0x4C, /**<2560×1600 reduced blanking */
HDMI_DMT_2560x1600_60 = 0x4D, /**<2560×1600 60 Hz */
HDMI_DMT_2560x1600_75 = 0x4E, /**<2560×1600 75 Hz */
HDMI_DMT_2560x1600_85 = 0x4E, /**<2560×1600 85 Hz */
HDMI_DMT_2560x1600_120 = 0x50, /** reduced blanking */
HDMI_DMT_1366x768_60 = 0x51, /**<1366×768 60Hz */
HDMI_DMT_1080p_60 = 0x52, /**<Same as 1080p60 in CEA above */
HDMI_DMT_1600x900_RB = 0x53, /**<1600×900 reduced blanking */
HDMI_DMT_2048x1152_RB = 0x54, /**<2048×1152 reduced blanking */
HDMI_DMT_720p_60 = 0x55, /**<Same as 720p60 in CEA above */
HDMI_DMT_1366x768_RB = 0x56, /**<1366×768 reduced blanking */

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();	               	
	}
}