Koneksi MMC dengan Mikrokontroler AVR Menggunakan SPI Mode

Berikut contoh schematic rangkaiannya.

Berikut beberapa command yang digunakan.

Command
Index

Argument

Response

Data

Abbreviation

Description

CMD0 None(0) R1 No GO_IDLE_STATE Software reset.
CMD1 None(0) R1 No SEND_OP_COND Initiate initialization process.
ACMD41(*1) *2 R1 No APP_SEND_OP_COND For only SDC. Initiate initialization process.
CMD8 *3 R7 No SEND_IF_COND For only SDC V2. Check voltage range.
CMD9 None(0) R1 Yes SEND_CSD Read CSD register.
CMD10 None(0) R1 Yes SEND_CID Read CID register.
CMD12 None(0) R1b No STOP_TRANSMISSION Stop to read data.
CMD16 Block
length[31:0]
R1 No SET_BLOCKLEN Change R/W block size.
CMD17 Address[31:0] R1 Yes READ_SINGLE_BLOCK Read a block.
CMD18 Address[31:0] R1 Yes READ_MULTIPLE_BLOCK Read multiple blocks.
CMD23 Number of
blocks[15:0]
R1 No SET_BLOCK_COUNT For only MMC. Define number of blocks to transfer
with next multi-block read/write command.
ACMD23(*1) Number of
blocks[22:0]
R1 No SET_WR_BLOCK_ERASE_COUNT For only SDC. Define number of blocks to pre-erase
with next multi-block write command.
CMD24 Address[31:0] R1 Yes WRITE_BLOCK Write a block.
CMD25 Address[31:0] R1 Yes WRITE_MULTIPLE_BLOCK Write multiple blocks.
CMD55(*1) None(0) R1 No APP_CMD Leading command of ACMD<n> command.
CMD58 None(0) R3 No READ_OCR Read OCR.
*1:ACMD<n> means a command sequense of CMD55-CMD<n>.
*2: Rsv(0)[31], HCS[30], Rsv(0)[29:0]
*3: Rsv(0)[31:12], Supply Voltage(1)[11:8], Check Pattern(0xAA)[7:0]

Berikut adalah timming diagram pada pengiriman command.

Berikut adalah format data ketika write/read data.

Lengkapnya sebagai berikut.



Berikut adalah timming diagram dari simulasi dari file http://rapidshare.com/files/71131573/SD_MMC.rar dari web http://www.sonsivri.to/forum/index.php?topic=6658.0

Dummy Clock

CMD0

CMD1

CMD16

CMD17

Timming diagram keseluruhan.

Timming diagram CMD17 sebelum menerima data.

Timming diagram CMD17 saat menerima data.

Timming diagram CMD17 saat menerima token dan data awal.

 

Berikut adalah program yang saya buat untuk koneksi dengan MMC via SPI yang kemudian hasilnya saya kirim lewat UART yang kemudian masuk Terminal pada PC. Compiler yang saya gunakan adalah CodevisionAVR. Yang saya lakukan adalah mencoba berapa command; -membuat inisialisasi MMC agar bisa digunakan pada mode SPI,-menulis data lalu membacanya lagi. Konfigurasi PIN yang saya gunakan adalah MOSI ke DI, MISO ke DO, SCK ke CLK, SS ke CS.

/*****************************************************
Chip type           : ATmega128
Program type        : Application
Clock frequency     : 11.059200 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 1024
*****************************************************/

#include <mega128.h>  
#include <delay.h>
#include <io.h>  
#ifndef SPIF
#define SPIF 7
#endif

// SPI functions
#include <spi.h> 

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x12 ;PORTD
#endasm
#include <lcd.h> 

#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7

#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)

// USART0 Receiver buffer
#define RX_BUFFER_SIZE0 8
char rx_buffer0[RX_BUFFER_SIZE0];

#if RX_BUFFER_SIZE0<256
unsigned char rx_wr_index0,rx_rd_index0,rx_counter0;
#else
unsigned int rx_wr_index0,rx_rd_index0,rx_counter0;
#endif

// This flag is set on USART0 Receiver buffer overflow
bit rx_buffer_overflow0;

// USART0 Receiver interrupt service routine
interrupt [USART0_RXC] void usart0_rx_isr(void)
{
char status,data;
status=UCSR0A;
data=UDR0;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
   {
   rx_buffer0[rx_wr_index0]=data;
   if (++rx_wr_index0 == RX_BUFFER_SIZE0) rx_wr_index0=0;
   if (++rx_counter0 == RX_BUFFER_SIZE0)
      {
      rx_counter0=0;
      rx_buffer_overflow0=1;
      };
   };
}

#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART0 Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter0==0);
data=rx_buffer0[rx_rd_index0];
if (++rx_rd_index0 == RX_BUFFER_SIZE0) rx_rd_index0=0;
#asm("cli")
--rx_counter0;
#asm("sei")
return data;
}
#pragma used-
#endif

// USART0 Transmitter buffer
#define TX_BUFFER_SIZE0 8
char tx_buffer0[TX_BUFFER_SIZE0];

#if TX_BUFFER_SIZE0<256
unsigned char tx_wr_index0,tx_rd_index0,tx_counter0;
#else
unsigned int tx_wr_index0,tx_rd_index0,tx_counter0;
#endif

// USART0 Transmitter interrupt service routine
interrupt [USART0_TXC] void usart0_tx_isr(void)
{
if (tx_counter0)
   {
   --tx_counter0;
   UDR0=tx_buffer0[tx_rd_index0];
   if (++tx_rd_index0 == TX_BUFFER_SIZE0) tx_rd_index0=0;
   };
}

#ifndef _DEBUG_TERMINAL_IO_
// Write a character to the USART0 Transmitter buffer
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while (tx_counter0 == TX_BUFFER_SIZE0);
#asm("cli")
if (tx_counter0 || ((UCSR0A & DATA_REGISTER_EMPTY)==0))
   {
   tx_buffer0[tx_wr_index0]=c;
   if (++tx_wr_index0 == TX_BUFFER_SIZE0) tx_wr_index0=0;
   ++tx_counter0;
   }
else
   UDR0=c;
#asm("sei")
}
#pragma used-
#endif

// Standard Input/Output functions
#include <stdio.h>

#define ss_ PORTB.0
// Declare your global variables here
unsigned char   index
                ,argument[4]
                ,CRC
                ,data[4]
                ,kata[16];
unsigned int i;
void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=0 State1=0 State0=0
PORTB=0x00;
DDRB=0x07;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Port E initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTE=0x00;
DDRE=0x00;

// Port F initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTF=0x00;
DDRF=0x00;

// Port G initialization
// Func4=In Func3=In Func2=In Func1=In Func0=In
// State4=T State3=T State2=T State1=T State0=T
PORTG=0x00;
DDRG=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
ASSR=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
OCR1CH=0x00;
OCR1CL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// Timer/Counter 3 initialization
// Clock source: System Clock
// Clock value: Timer 3 Stopped
// Mode: Normal top=FFFFh
// Noise Canceler: Off
// Input Capture on Falling Edge
// OC3A output: Discon.
// OC3B output: Discon.
// OC3C output: Discon.
// Timer 3 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR3A=0x00;
TCCR3B=0x00;
TCNT3H=0x00;
TCNT3L=0x00;
ICR3H=0x00;
ICR3L=0x00;
OCR3AH=0x00;
OCR3AL=0x00;
OCR3BH=0x00;
OCR3BL=0x00;
OCR3CH=0x00;
OCR3CL=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
// INT3: Off
// INT4: Off
// INT5: Off
// INT6: Off
// INT7: Off
EICRA=0x00;
EICRB=0x00;
EIMSK=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
ETIMSK=0x00;    

// USART0 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART0 Receiver: On
// USART0 Transmitter: On
// USART0 Mode: Asynchronous
// USART0 Baud rate: 9600
UCSR0A=0x00;
UCSR0B=0xD8;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x47;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 2764.800 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x50;
SPSR=0x00; 

// Global enable interrupts
#asm("sei")
lcd_init(16);                     

//_________________beri clock awal_______________
delay_ms(2);
ss_ =1; //cs=1  
for(i=0;i<10;i++)spi(0xFF); //74 cycle 
delay_us(10);
ss_ =0; //cs=0;   
printf("dummy clock \n\r");   //kirim UART ke Terminal PC
delay_ms(2);   
//_________________CMD0_______________
for(i=0;i<16;i++)spi(0xFF); //8x16 cycle 
//'40 00 00 00 00 95'
spi(0x40);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x95);      
spi(0xFF);  //8clock cycle     
data[0]=spi(0xFF); //get data    
delay_us(5);

printf("CMD0:%d \n\r",data[0]);  //kirim UART ke Terminal PC          
//_________________CMD1_______________
for(i=0;i<16;i++)spi(0xFF); //8x16 cycle
//'41 00 00 00 00 95'
spi(0x41);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x95);      
spi(0xFF);  //8clock cycle     
data[0]=spi(0xFF); //get data    
delay_us(5);

printf("CMD1:%d \n\r",data[0]);   //kirim UART ke Terminal PC

//_________________CMD16_______________
for(i=0;i<16;i++)spi(0xFF); //8x16 cycle
//'50 00 00 00 00 95'
spi(0x50);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x20);  //fat32
spi(0x95);      
spi(0xFF);  //8clock cycle     
data[0]=spi(0xFF); //get data    
delay_us(5);

printf("CMD16:%d \n\r",data[0]);    //kirim UART ke Terminal PC

//_________________CMD10_______________
for(i=0;i<16;i++)spi(0xFF); //8x16 cycle
//'50 00 00 00 00 95'
spi(0x4A);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x95);      
spi(0xFF);  //8clock cycle     
data[0]=spi(0xFF); //get data    
delay_us(5);

printf("CMD10/CID READ:%d \n\r",data[0]);    //kirim UART ke Terminal PC

while(spi(0xFF)!=0xFE);
for(i=0;i<16;i++)printf("%c \n\r",spi(0xFF));  //kirim data ke UART ke Terminal PC
spi(0xFF);  //8clock cycle  
spi(0xFF);  //8clock cycle           

//_________________CMD9_______________
for(i=0;i<16;i++)spi(0xFF); //8x16 cycle
//'50 00 00 00 00 95'
spi(0x49);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x95);      
spi(0xFF);  //8clock cycle     
data[0]=spi(0xFF); //get data    
delay_us(5);

printf("CMD9/CSD READ:%d \n\r",data[0]);    //kirim UART ke Terminal PC

while(spi(0xFF)!=0xFE);
for(i=0;i<16;i++)printf("%d \n\r",spi(0xFF));
spi(0xFF);  //8clock cycle  
spi(0xFF);  //8clock cycle     

//_________________CMD24_______________
for(i=0;i<16;i++)spi(0xFF); //8x16 cycle
//'50 00 00 00 00 95'
spi(0x58);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x95);      
spi(0xFF);  //8clock cycle     
data[0]=spi(0xFF); //get data    
delay_us(5);

printf("CMD24:%d \n\r",data[0]);    //kirim UART ke Terminal PC

for(i=0;i<18;i++)spi(0xFF); //8x18 cycle
spi(0xFE);   //token
for(i=0;i<32;i++)spi(49+i); //kirim data angka 1 dalam ASCII dan 32 kode dst
spi(0xFF);  //CRC
spi(0xFF);  //CRC

while(spi(0xFF)!=0xFF)              

//_________________CMD17_______________
for(i=0;i<16;i++)spi(0xFF); //8x16 cycle
//'50 00 00 00 00 95'
spi(0x51);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x00);
spi(0x95);      
spi(0xFF);  //8clock cycle     
data[0]=spi(0xFF); //get data    
delay_us(5);

printf("CMD17:%d \n\r",data[0]);   

while(spi(0xFF)!=0xFE);
//baca data lalu kirim UART ke Terminal PC
for(i=0;i<32;i++)printf("READ-%d:%c \n\r",i,spi(0xFF));
spi(0xFF);  //8clock cycle  
spi(0xFF);  //8clock cycle         
//__________________________________________  

while (1)
      {
      // Place your code here

      };
}

Berikut adalah program yang lainnya yang sudah saya buat fungsinya.

/*****************************************************
Chip type           : ATmega128
Program type        : Application
Clock frequency     : 11.059200 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 1024
*****************************************************/

#include <mega128.h>  
#include <delay.h>
#include <io.h>  
#ifndef SPIF
#define SPIF 7
#endif

// SPI functions
#include <spi.h> 

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x12 ;PORTD
#endasm
#include <lcd.h> 

#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7

#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)

// USART0 Receiver buffer
#define RX_BUFFER_SIZE0 8
char rx_buffer0[RX_BUFFER_SIZE0];

#if RX_BUFFER_SIZE0<256
unsigned char rx_wr_index0,rx_rd_index0,rx_counter0;
#else
unsigned int rx_wr_index0,rx_rd_index0,rx_counter0;
#endif

// This flag is set on USART0 Receiver buffer overflow
bit rx_buffer_overflow0;

// USART0 Receiver interrupt service routine
interrupt [USART0_RXC] void usart0_rx_isr(void)
{
char status,data;
status=UCSR0A;
data=UDR0;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
   {
   rx_buffer0[rx_wr_index0]=data;
   if (++rx_wr_index0 == RX_BUFFER_SIZE0) rx_wr_index0=0;
   if (++rx_counter0 == RX_BUFFER_SIZE0)
      {
      rx_counter0=0;
      rx_buffer_overflow0=1;
      };
   };
}

#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART0 Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter0==0);
data=rx_buffer0[rx_rd_index0];
if (++rx_rd_index0 == RX_BUFFER_SIZE0) rx_rd_index0=0;
#asm("cli")
--rx_counter0;
#asm("sei")
return data;
}
#pragma used-
#endif

// USART0 Transmitter buffer
#define TX_BUFFER_SIZE0 8
char tx_buffer0[TX_BUFFER_SIZE0];

#if TX_BUFFER_SIZE0<256
unsigned char tx_wr_index0,tx_rd_index0,tx_counter0;
#else
unsigned int tx_wr_index0,tx_rd_index0,tx_counter0;
#endif

// USART0 Transmitter interrupt service routine
interrupt [USART0_TXC] void usart0_tx_isr(void)
{
if (tx_counter0)
   {
   --tx_counter0;
   UDR0=tx_buffer0[tx_rd_index0];
   if (++tx_rd_index0 == TX_BUFFER_SIZE0) tx_rd_index0=0;
   };
}

#ifndef _DEBUG_TERMINAL_IO_
// Write a character to the USART0 Transmitter buffer
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while (tx_counter0 == TX_BUFFER_SIZE0);
#asm("cli")
if (tx_counter0 || ((UCSR0A & DATA_REGISTER_EMPTY)==0))
   {
   tx_buffer0[tx_wr_index0]=c;
   if (++tx_wr_index0 == TX_BUFFER_SIZE0) tx_wr_index0=0;
   ++tx_counter0;
   }
else
   UDR0=c;
#asm("sei")
}
#pragma used-
#endif

// Standard Input/Output functions
#include <stdio.h>

#define ss_ PORTB.0
// Declare your global variables here
unsigned char   count;

void dummy_clock()
{
unsigned char i;
        ss_ =1; //cs=1  
        for(i=0;i<10;i++)spi(0xFF); //74 cycle 
        delay_us(10);
        ss_ =0; //cs=0;   
}                     

unsigned char CMD_R1response(unsigned char CMD,unsigned char ARG1,unsigned char ARG2,unsigned char ARG3,unsigned char ARG4)
{   
unsigned char   r1_respone
                ,i;
        for(i=0;i<16;i++)spi(0xFF); //8x16 cycle 
        spi(CMD+64);
        spi(ARG1);
        spi(ARG2);
        spi(ARG3);
        spi(ARG4);
        spi(0x95);      
        do r1_respone=spi(0xFF); //get data    
        while(r1_respone==0xFF);
        delay_us(5);
        return(r1_respone);
} 

unsigned char data_[512];
void read_data(unsigned char jum_byte)
{
unsigned int i;
        while(spi(0xFF)!=0xFE);  //token
        for(i=0;i<jum_byte;i++)data_[i]=spi(0xFF);
        spi(0xFF);  //8clock cycle  
        spi(0xFF);  //8clock cycle 
}    

void clear_data_()
{
 unsigned int i; 
        for(i=0;i<512;i++)data_[i]=0;
}

void write_data(unsigned char jum_byte)
{
 unsigned int i;                                

        for(i=0;i<18;i++)spi(0xFF); //8x18 cycle
        spi(0xFE);  //token
        for(i=0;i<jum_byte;i++)spi(data_[i]);
        spi(0xFF);  //8clock cycle  
        spi(0xFF);  //8clock cycle  
}

void write_data_str(unsigned char jum_byte,unsigned char size_text , char flash *str)
{
 unsigned int i;                                

        for(i=0;i<18;i++)spi(0xFF); //8x18 cycle
        spi(0xFE);  //token
        for(i=0;i<size_text;i++)spi(str[i]);
        for(i=size_text-1;i<jum_byte;i++)spi(0);
        spi(0xFF);  //8clock cycle  
        spi(0xFF);  //8clock cycle 
}

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=0 State1=0 State0=0
PORTB=0x00;
DDRB=0x07;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Port E initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTE=0x00;
DDRE=0x00;

// Port F initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTF=0x00;
DDRF=0x00;

// Port G initialization
// Func4=In Func3=In Func2=In Func1=In Func0=In
// State4=T State3=T State2=T State1=T State0=T
PORTG=0x00;
DDRG=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
ASSR=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
OCR1CH=0x00;
OCR1CL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// Timer/Counter 3 initialization
// Clock source: System Clock
// Clock value: Timer 3 Stopped
// Mode: Normal top=FFFFh
// Noise Canceler: Off
// Input Capture on Falling Edge
// OC3A output: Discon.
// OC3B output: Discon.
// OC3C output: Discon.
// Timer 3 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR3A=0x00;
TCCR3B=0x00;
TCNT3H=0x00;
TCNT3L=0x00;
ICR3H=0x00;
ICR3L=0x00;
OCR3AH=0x00;
OCR3AL=0x00;
OCR3BH=0x00;
OCR3BL=0x00;
OCR3CH=0x00;
OCR3CL=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
// INT3: Off
// INT4: Off
// INT5: Off
// INT6: Off
// INT7: Off
EICRA=0x00;
EICRB=0x00;
EIMSK=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
ETIMSK=0x00;    

// USART0 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART0 Receiver: On
// USART0 Transmitter: On
// USART0 Mode: Asynchronous
// USART0 Baud rate: 9600
UCSR0A=0x00;
UCSR0B=0xD8;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x47;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 2764.800 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x50;
SPSR=0x00; 

// Global enable interrupts
#asm("sei")
lcd_init(16);                     

dummy_clock();  
printf("dummy clock \n\r");

printf("CMD0:%d \n\r",CMD_R1response(0,0,0,0,0));

printf("CMD1:%d \n\r",CMD_R1response(1,0,0,0,0));

printf("CMD16:%d \n\r",CMD_R1response(16,0,0,0,32));

printf("CMD10:%d \n\r",CMD_R1response(10,0,0,0,0));     
read_data(16);                        
for(count=0;count<16;count++)printf("%d \n\r",data_[count]);
clear_data_(); 

printf("CMD9:%d \n\r",CMD_R1response(9,0,0,0,0));     
read_data(16);                        
for(count=0;count<16;count++)printf("%d \n\r",data_[count]);
clear_data_();

printf("CMD24:%d \n\r",CMD_R1response(24,0,0,1,0));                
write_data_str(32,21,"tes data kirim\n\rMMC\n\r");  
clear_data_();  

printf("CMD24:%d \n\r",CMD_R1response(24,0,0,0,0));   
data_[0] = 'U';           
write_data(32);  
clear_data_(); 

printf("CMD17:%d \n\r",CMD_R1response(17,0,0,0,0));     
read_data(32);                        
for(count=0;count<32;count++)printf("%c \n\r",data_[count]);   
clear_data_();          

printf("CMD17:%d \n\r",CMD_R1response(17,0,0,1,0));     
read_data(32);                        
for(count=0;count<32;count++)printf("%c",data_[count]);   
clear_data_(); 

printf("CMD17:%d \n\r",CMD_R1response(17,0,0,0,0));     
read_data(32);                        
for(count=0;count<32;count++)printf("%c \n\r",data_[count]);   
clear_data_();  

while (1)
      {
      // Place your code here

      };
}

Berikut project file simulasi dengan compiler CodevisionAVR dan Simulator Proteus 7.7

http://www.mediafire.com/file/m7go0c1pf457kib/MMC_myfile.rar

________________________________________

DAFTAR PUSTAKA

http://nawattlabs.com/index.php/corporate/blog/26-sd-mmc-programming

http://www.sonsivri.to/forum/index.php?topic=6658.0

http://elm-chan.org/docs/mmc/mmc_e.html

http://www.mikroe.com/download/eng/documents/compilers/mikrobasic/pro/avr/help/mmc_library.htm

http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

http://elm-chan.org/docs/spi_e.html

http://www.ulrichradig.de/site/arm_projekts/mmc_sd/doc/MMCSDTimming.pdf

http://www.innovativeelectronics.com/innovative_electronics/pro_ems_smd_mmc_fram.htm

http://www.innovativeelectronics.com/innovative_electronics/download_files/artikel/AN_SD_CVAVR.pdf

http://www.innovativeelectronics.com/innovative_electronics/download_files/artikel/AN_SD_FAT.pdf

Membuat PIN Rx UART 8N1 dari PORT Biasa Mikrokontroler AVR (CodeVision AVR)

Berikut ini adalah program yang saya gunakan untuk menerima data serial dari fungsi biasa pin IO. Metode yang saya gunakan adalah menangkap signal yang dikirim dengan sela waktu perioda_baudrate sebanyak data bit yang dikirim, dalam kasus ini berformat UART 8N1. Untuk sela waktu, saya menggunakan fungsi delay my_delay_us() yang dibuat sendiri dari fungsi library bawaan karena fungsi delay_us() tidak bisa diisi dengan variabel. Akan tetapi hal itu menjadikan fungsi my_delay_us() tidak presisi. Untuk itu saya menambahkan konstanta_error untuk men-tunning agar nilai delay tepat. konstanta_error saya dapat dengan men-tunning-nya dengan terlebih dahulu melihat signal perioda dari my_delay_us(konstanta_error) dengan mengeluarkan HIGH dengan sela waktu tersebut kemudia juga dengan LOW pada salah satu PORT IO dan mencocokan dengan hitungan perioda baudrate yang digunakan. Dengan begitu, bisa didapatkan konstanta_error yang tepat.

/*****************************************************
Chip type               : ATmega16
Program type            : Application
AVR Core Clock frequency: 11.059200 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

#include mega16.h>
#include delay.h>
#include stdio.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x1B ;PORTA
#endasm
#include lcd.h>

unsigned char kata[16];

// Declare your global variables here
#define my_RXport PINC.0 //set pin rx
#define my_RXport_dir DDRC.0 //direksi port

void my_delay_us(int n)
{
    while(--n)
    delay_us(1);
}

int perioda_baudrate;
void rx_init()
{
    int baudrate = 9600; //set baudrate
    int konstanta_error = -54; //ditunning sampai mendapat hasil optimal
    my_RXport_dir = 0; //set sebagai input
    perioda_baudrate = (1000000/baudrate) + konstanta_error; //dalam mikro second
}

unsigned char my_getchar()
{
    unsigned char   urut_data
                    ,data=0;
    while(my_RXport){}; //tunggu kepada data logic LOW
    my_delay_us(perioda_baudrate);
    for(urut_data=0;urut_data<8;urut_data++)
    {
        data = data >> 1;
        if(my_RXport)
            data += 128;
        else
            data += 0;
        my_delay_us(perioda_baudrate);
    }
    return(data);
}

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// LCD module initialization
lcd_init(16);
rx_init();
while (1)
      {
      // Place your code here
        sprintf(kata,"%c",my_getchar());   
        lcd_puts(kata);    
      };
}

Aplikasi Serialport Berbasis Console Application Visual C# 2010 Express

Pertama-tama buatlah sebuah project baru.

Lalu pada bagian Program.cs masukan kode berikut.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;

namespace SerialTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] names = SerialPort.GetPortNames();
            Console.WriteLine("Serial ports:");
            foreach (string name in names)
                Console.WriteLine(name);
            Console.Write("Choose one:");
            SerialPort p = new SerialPort(Console.ReadLine());
            p.DataReceived += new SerialDataReceivedEventHandler(p_DataReceived);
            p.Open();
            string line;
            do
            {
                line = Console.ReadLine();
                p.Write(line);
            } while (line != "quit");
            p.Close();
        }

        static void p_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Console.WriteLine(
                (sender as SerialPort).ReadExisting());
        }
    }
}

Setelah itu, jangan lupa save program yang sudah dibuat. Run program (F5). Program bisa dicoba berkomunikasi dengan Hyperterminal atau aplikasi serial port lainnya dengan bantuan VSPE (Virtual Serial Port Emulator) yang bisa di download di http://www.eterlogic.com/downloads/SetupVSPE.zip

Pada program yang sudah dibuat tadi, setelah dijalankan, untuk memilih COM, langsung saja diketik nama COM nya. Misal COM5. Untuk mengirim data, tekan enter. Untuk keluar dari program, ketik “quit” lalu tekan enter.

VSPE (Virtual Serial Port Emulator).

Tampilan program.

___________________________

Daftar Pustaka

http://balau82.wordpress.com/2009/04/18/simplest-serial-port-terminal-in-csharp/

Aplikasi Serial Terminal Berbasis Java Menggunakan NetBeans IDE (Menggunakan SimpleSerialNative.dll)

_________________________________________

Buatlah New Project.

Pilih Java Aplication lalu Next. Setelah itu isilah Project Name dengan nama java serial dan uncheck Create Main Class lalu Finish.

Setelah itu, buatlah form baru pada Source Packages dengan cara klik kanan pada <default package> lalu pilih New, lalu JFrame Form…

Lalu isilah Class Name dengan serialport lalu Finish.

Lalu copy file SimpleSerial.java dan SimpleSerialNative.java ke folder src pada folder project yang dikerjakan dan copy juga file SimpleSerialNative.dll ke directory folder project sehingga tampak pada window Projects seperti gambar di bawah ini.

Setelah itu buatlah form seperti di bawah ini.

Control Property Value
JFrame Title Java Serial Port
Status_label Text Status:
Receive_textarea lineWrap True
Receive_textarea wrapStyleWord True

Lalu ketiklah kode di bawah ini. kode di bawah adalah kode untuk form GUI

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * java_terminal.java
 *
 * Created on Aug 21, 2011, 11:12:42 PM
 */
/**
 *
 * @author Administrator
 */
import javax.swing.*;

public class java_terminal extends javax.swing.JFrame {

    /** Creates new form java_terminal */
    public java_terminal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    //
    private void initComponents() {

        textField1 = new java.awt.TextField();
        connect_button = new javax.swing.JButton();
        disconnect_button = new javax.swing.JButton();
        com_label = new javax.swing.JLabel();
        com_combobox = new javax.swing.JComboBox();
        send_textarea = new javax.swing.JTextField();
        kirim_button = new javax.swing.JButton();
        baudrate_combobox = new javax.swing.JComboBox();
        baudrate_label = new javax.swing.JLabel();
        format_data = new javax.swing.JLabel();
        status_label = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        receive_textarea = new javax.swing.JTextArea();
        clear_button = new javax.swing.JButton();

        textField1.setText("textField1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("WangReady Java Serial Terminal");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        connect_button.setText("Connect");
        connect_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                connect_buttonActionPerformed(evt);
            }
        });

        disconnect_button.setText("Disconnect");
        disconnect_button.setEnabled(false);
        disconnect_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                disconnect_buttonActionPerformed(evt);
            }
        });

        com_label.setText("COM yg tersedia");

        kirim_button.setText("Kirim");
        kirim_button.setEnabled(false);
        kirim_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kirim_buttonActionPerformed(evt);
            }
        });

        baudrate_combobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "110", "300", "600", "1200", "2400", "4800", "9600", "14400", "19200", "38400", "56000", "57600", "115200" }));

        baudrate_label.setText("Baudrate");

        format_data.setText("Format data 8N1");

        status_label.setText("Status:");
        status_label.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        receive_textarea.setColumns(20);
        receive_textarea.setEditable(false);
        receive_textarea.setLineWrap(true);
        receive_textarea.setRows(5);
        receive_textarea.setWrapStyleWord(true);
        receive_textarea.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane1.setViewportView(receive_textarea);

        clear_button.setText("Bersihkan layar data terima");
        clear_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clear_buttonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(status_label, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(baudrate_combobox, javax.swing.GroupLayout.Alignment.TRAILING, 0, 87, Short.MAX_VALUE)
                            .addComponent(com_combobox, javax.swing.GroupLayout.Alignment.TRAILING, 0, 87, Short.MAX_VALUE)
                            .addComponent(com_label)
                            .addComponent(baudrate_label, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(format_data)
                            .addComponent(connect_button, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                            .addComponent(disconnect_button, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(clear_button)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(send_textarea, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(kirim_button)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(com_label)
                        .addGap(3, 3, 3)
                        .addComponent(com_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(baudrate_label)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(baudrate_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(format_data)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(connect_button))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(disconnect_button)
                    .addComponent(clear_button))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(status_label, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(send_textarea, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                    .addComponent(kirim_button))
                .addContainerGap())
        );

        pack();
    }//
    private SimpleSerialNative ss;
    private void connect_buttonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        String com_string = com_combobox.getSelectedItem().toString();
        int com_port = Integer.parseInt(com_string.substring(3));
        int baudrate = Integer.parseInt(baudrate_combobox.getSelectedItem().toString());
        try{
            ss = new SimpleSerialNative(com_port,baudrate, 8, SimpleSerialNative.ONESTOPBIT, SimpleSerialNative.NOPARITY);
            if(!ss.isValid()){
                status_label.setText("Status: PORT"+com_port +" tidak bisa digunakan. Coba PORT yang lain");
            }else{
                status_label.setText("Status: Connected... COM"+Integer.toString(com_port)+" Baudrate:"+Integer.toString(baudrate)+"bpsCatatan: Disconect apabila ingin close");
                disconnect_button.setEnabled(true);
                kirim_button.setEnabled(true);
                connect_button.setEnabled(false);
                setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

                new Thread(new ReadThread()).start();
            }
        }
        catch(Exception e){
            status_label.setText("Status: PORT tidak bisa digunakan. Coba PORT yang lain");
        }
    }

 /**
 * Buffer to hold the reading
 */
private byte[] readBuffer = new byte[400];

private void readSerial() {
    try {
        int availableBytes = ss.available();
        if (availableBytes > 0) {
            // Print it out
           receive_textarea.append(ss.readString());
        }
    } catch (Exception e) {
    }
}

private  class ReadThread implements Runnable {
        @Override
    public void run() {
        while(true) {
            readSerial();
        }
        }
    }

    private void disconnect_buttonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
         ss.close();
         status_label.setText("Status: Disconnected");
         disconnect_button.setEnabled(false);
         kirim_button.setEnabled(false);
         connect_button.setEnabled(true);
         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    private void kirim_buttonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        ss.writeString(send_textarea.getText());
        send_textarea.setText(null);
    }

    private void clear_buttonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        receive_textarea.setText(null);
    }

    private Object makeObj(final String item)  {
     return new Object() {@Override
 public String toString() { return item; } };
   }

    private void formWindowOpened(java.awt.event.WindowEvent evt) {
        // TODO add your handling code here:
        for(int ii = 0;ii < 50;ii++){
            try{
                ss = new SimpleSerialNative(ii+1);
                if(ss.available()==0){
                    com_combobox.addItem(makeObj("COM" + Integer.toString(ii + 1)));
                }
                ss.close();
            }
            catch(Exception e){

            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new java_terminal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JComboBox baudrate_combobox;
    private javax.swing.JLabel baudrate_label;
    private javax.swing.JButton clear_button;
    private javax.swing.JComboBox com_combobox;
    private javax.swing.JLabel com_label;
    private javax.swing.JButton connect_button;
    private javax.swing.JButton disconnect_button;
    private javax.swing.JLabel format_data;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton kirim_button;
    private javax.swing.JTextArea receive_textarea;
    private javax.swing.JTextField send_textarea;
    private javax.swing.JLabel status_label;
    private java.awt.TextField textField1;
    // End of variables declaration
}

Setelah semuanya selesai, Run Project atau F6. Jika berhasil, lalu Build Project atau F11, maka akan muncul forlde dist pada folder project yang berisi file .jar yang siap dijalankan. Akan tetapi file .jar tadi memerlukan file SimpleSerialNative.dll, maka copy file tersebut ke folder dist.

Berikut file yang berisi SimpleSerial.zip yang digunakan sebagai library.

Berikut file project.

http://www.mediafire.com/file/vtmd6kv1tb8sa2m/wangready-java%20terminal.rar

update REVISI

http://www.mediafire.com/?fclogl61qpldqq8

_______________________________

Daftar Pustaka

alumni.media.mit.edu/~benres/simpleserial/

Mengirim Ulang Data UART 8N1 dengan Baud Rate Berbeda (CodeVision AVR)

Berikut adalah contoh program yang akan menerima data dengan baud rate 57600 bps dan mengirimnya dengan baudrate 4800 bps.  PIN terima adalah PIN Rx UART sedangkan Tx menggunakan header file UART_8N1_TX. Pada contoh di bawah ini PORT Tx yang digunakan adalah PORTD.7.

#include <mega8.h>      
#include "UART_8N1_TX.h"

#ifndef RXB8
#define RXB8 1
#endif

#ifndef TXB8
#define TXB8 0
#endif

#ifndef UPE
#define UPE 2
#endif

#ifndef DOR
#define DOR 3
#endif

#ifndef FE
#define FE 4
#endif

#ifndef UDRE
#define UDRE 5
#endif

#ifndef RXC
#define RXC 7
#endif

#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<DOR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)

// USART Receiver buffer
#define RX_BUFFER_SIZE 8
char rx_buffer[RX_BUFFER_SIZE];

#if RX_BUFFER_SIZE<256
unsigned char rx_wr_index,rx_rd_index,rx_counter;
#else
unsigned int rx_wr_index,rx_rd_index,rx_counter;
#endif

// This flag is set on USART Receiver buffer overflow
bit rx_buffer_overflow;

// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,data;
status=UCSRA;
data=UDR;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
   {
   rx_buffer[rx_wr_index]=data;
   if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
   if (++rx_counter == RX_BUFFER_SIZE)
      {
      rx_counter=0;
      rx_buffer_overflow=1;
      };
   };
}

#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter==0);
data=rx_buffer[rx_rd_index];
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
#asm("cli")
--rx_counter;
#asm("sei")
return data;
}
#pragma used-
#endif

// Standard Input/Output functions
#include <stdio.h>

// Declare your global variables here

void main(void)
{
// Declare your local variables here
unsigned char data;
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: Off
// USART Mode: Asynchronous
// USART Baud Rate: 57600
UCSRA=0x00;
UCSRB=0x90;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x10;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// Global enable interrupts
#asm("sei")

init_my_putchar(4800,7);
while (1)
      {
      // Place your code here
      data = getchar();
      #asm("cli")
      my_putchar(data);   
      #asm("sei")
      };
}

Berikut adalah file project dari program di atas yang bisa di download.

http://www.mediafire.com/file/sm36qg8dq4m4ad7/bps%20to%20bps.rar

Membuat PIN Tx UART 8N1 dari PORT Biasa Mikrokontroler AVR (CodeVision AVR)

Berikut header file yang digunakan untuk mengirim data. Pada header file di bawah, PORT yang digunakan adalah PORTD, tapi bisa diganti dengan PORT yang lainnya. K_error delay adalah variabel yang diatur untuk mendapatkan lebar perioda yang tepat untuk start bit. Sedangkan K_error_delay_data adalah variabel yang diatur untuk mendapatkan lebar perioda yang tepat untuk bit data. Kedua variabel tersebut diatur dengan cara membandingkan lebar signal yang dilihat pada osiloskop. Cara yang cukup sederhana bisa menggunakan software simulasi.

//============================================
//AUTHOR : wangready.wordpress.com
//FORMAT UART:  8 bit data
//              None Parity
//              1 Stop bit
//Setting PORET ditentukan pada header file UART_8N1_TX.h.
//sedangkan nomor PORT yang digunakan bisa diakses dari
//peosedur init_my_putchar(unsigned int baud_rate, unsigned int BIT).
//K_error_delay dan K_error_delay_data diatur agar mendapatkan
//baudrate yang sesuai.     
//============================================

#ifndef UART_8N1_TX
#define UART_8N1_TX

#include <delay.h>

#define _PORT_TX PORTD  //SET PORT TX
#define _DDR_TX DDRD    //SET DDR TX

void my_delay_us(unsigned int n)
{
    while(n--)
    {
        delay_us(1);
    };   
}

unsigned int    K_delay,
                K_error_delay = 100,                
                K_error_delay_data = -6,
                K_delay_data,
                BIT_global;
void init_my_putchar(unsigned int baud_rate, unsigned int BIT)
{
    BIT_global = BIT;
    _PORT_TX |= (0x01<<BIT);
    _DDR_TX |= (0x01<<BIT);  

    K_delay = (1000000/baud_rate) - K_error_delay;
    K_delay_data = K_delay - K_error_delay_data;
}

void my_putchar(unsigned char data)
{
unsigned char ii;
    _PORT_TX &= ~(0x01<<BIT_global);  //START BIT  
    my_delay_us(K_delay);

    for(ii = 0;ii < 8;ii++)
    {             
        if((data & 0x01) == 0x01)
        {
            _PORT_TX |= (0x01<<BIT_global);
        }else
        {
            _PORT_TX &= ~(0x01<<BIT_global);
        }
        data = (data>>1);   
        my_delay_us(K_delay_data);
    }

    _PORT_TX |= (0x01<<BIT_global);    //SET HIGH
    my_delay_us(K_delay);
}

#endif

Berikut contoh program utama untuk mikrokontroler ATmega8 dengan xtal 16MHz yang akan mengirim data karakter dari huruf ‘R’ dengan PIN TX menggunakan PORTD.7 setiap 500 ms.

#include <mega8.h>
#include "UART_8N1_TX.h"

void main(void)
{
init_my_putchar(4800, 7);
while (1)
      {
      my_putchar('R');
      delay_ms(500);
      };
}

Berikut project file dari program diatas yang bisa di download.

http://www.mediafire.com/file/hams5878vnscoka/UART%20PORT%20Tx.rar

Untuk simulasi bisa digunakan software Proteus dan untuk menghubungkan Proteus ke hyperterminal bisa digunakan Virtual Serial Port Emulator.

Virtual Serial Ports Emulator dari eterlogic.com

Virtual Serial Ports Emulator
The emulation solution

Version information: 0.938.4.846
  • Added Spy device
  • TcpServer and TcpClient devices now supports COM port read-only and COM port write-only modes
  • Fixed bug with localization of the device properties dialog
  • Added ability to reorganize devices (move up and down) when emulation is stopped
  • Fixed bug with COM port speed selection from Combo box (added missed values)
  • Reinitialization of failed devices (see Preferences => Advanced tab) disabled by default
  • Fixed French translation
  • File data stream: added output ability, now it can be used to write output to file
  • Updated documentation
Description

VSPE is intended to help software engineers and developers to create/debug/test applications that use serial ports. It is able to create various virtual devices to transmit/receive data. Unlike regular serial ports, virtual devices have special capabilities: for example, the same device can be opened more than once by different applications, that can be useful in many cases. With VSPE you are able to share physical serial port data for several applications, expose serial port to local network (via TCP protocol), create virtual serial port device pairs and so on.

Key features
  • Virtual device: connector
  • Virtual device: data splitter
  • Virtual device: pair
  • Mapper device
  • User mode device: TcpServer
  • User mode device: TcpClient
  • User mode device: Serial Redirector
  • User mode device: UDP Manager
  • User mode device: Bridge
  • Python scripting system
  • x86 and x86_64 processor architecture support
  • VSPE API (C/C++ header and static library) for native language developers
  • VSPE API Python bindings for Python developers
  • Embedded HTTP server
  • Data monitoring
Requirements
  • Operating system: Windows 2000, XP, Vista (32/64), Windows 7
FREE license for 32 bit platform (x86)

Virtual Serial Ports Emulator is a FREEWARE program on 32 bit platform and can be used absolutely free for any purpose.

FOR DEVELOPERS: You can also use FREE VSPE API key located in the distribution package to get access to internal VSPE functions.

FREE 32 bit platform VSPE API key (x86 only)

Please look for the FREE 32 bit VSPE API key in the distribution package (VSPE_API_32_KEY.txt in SetupVSPE.zip). Please note, that this key is valid for the current version only! After installing new VSPE version, you should replace old key with the new one.

DOWNLOAD

http://www.eterlogic.com/downloads/SetupVSPE.zip

Contoh aplikasi. Di-upload ulang dari situs http://www.youtube.com/watch?v=5pQ6gwv_Gcc

___________________________________________

Daftar Pustaka

http://www.edaboard.com/thread165710.html

http://www.eterlogic.com/Products.VSPE.html

http://www.eterlogic.com/Downloads.html

Komunikasi I2C pada Microcontroller AVR

Sumber:

http://www.robot-electronics.co.uk/acatalog/I2C_Tutorial.html

http://en.wikipedia.org/wiki/I%C2%B2C

SPC Motor Controller Manual Guide.

Help — CodeVisionAVR.

I2C (Inter-Integrated Circuit) (umumnya disebut sebagai “two-wire interface”). Berikut konfigurasi dari sistem I2C.

Berikut timing diagram dari komunikasi I2C.

Pada komunikasi I2C terdapat perangkat master dan slave. Master adalah perangkat yang mengatur jalur clock SCL. Sedangkan slave adalah perangkat yang merespon perintah master. Slave tidak dapat mengirim sinyal untuk dapat mentransfer data pada jalur I2C, hanya master yang dapat melakukannya.Dimungkinkan untuk memiliki banyak master, tapi hal tersebut tidak biasa.

Berikut adalah timing diagram dari sebuah master yang ingin meminta data yang terdiri dari dua sekuen khusus yang ditetapkan untuk I2C yaitu Start dan Stop.

Data terdiri dari 8 bit dan menjadi 9 bit dengan bit terakhir adalah ACK. ACK adalah sinyal yang dikirim oleh sinyal penerima. Jika perangkat penerima mengirim kembali bit low ACK, karena sudah menerima data dan berarti siap menerima data selanjutnya.   Jika sinyal ACK yang dikirim adalah high maka perangkat tersebut tidak dapat menerima data lebih lanjut dan master harus menghentikan transfer dengan mengirim Stop sequence.

Standar kecepatan clock (SCL) untuk I2C bisa mencapai 100KHz. Philips sebagai perusahaan yang memperkenalkan pertamakali I2C mendefinisikan beberapa tingkatan kecepatan: Fast mode, bisa mencapai 400KHz dan High Speed mode yang mencapai 3.4MHz. Untuk beberapa aplikasi pada perangkat yang sederhana tampaknya 100KHz sudah cukup.

Semua pengalamatan I2C terdiri dari 7bit atau 10bit. Penggunaan pengalamatan 10bit jarang. Biasanya yang banyak digunakan adalah pengalamatan 7bit. Berarti kita bisa mempunyai 128 perangkat yang akan tersambung ke bus, dari 0 sampai 127. Seperti pada gambar di atas yang terdiri dari 9bit terdapat R/W sebagai bit pengatur apakah maksud dari master adalah untuk write/menulis (nilai R/W bit = 0) data atau read/membaca (nilai R/W bit = 1) data dari slave.  Pada intinya data yang dikirim adalah 8bit dengan LSB adalah R/W bit.

Berikut contoh kode untuk master yang saya dapatkan dari http://www.robot-electronics.co.uk/acatalog/I2C_Tutorial.html jika ingin membuat kode sendiri. Contoh di bawah ini untuk mikrokontroler PIC akan tetapi tampaknya bisa digunakan untuk mikrokontroler lainnya yang mempunyai format pemograman yang sama.

#define SCL     TRISB4 // I2C bus
#define SDA     TRISB1 //
#define SCL_IN  RB4    //
#define SDA_IN  RB1    //

To initialize the ports set the output resisters to 0 and the tristate registers to 1 which disables the outputs and allows them to be pulled high by the resistors.
SDA = SCL = 1;
SCL_IN = SDA_IN = 0;

We use a small delay routine between SDA and SCL changes to give a clear sequence on the I2C bus. This is nothing more than a subroutine call and return.
void i2c_dly(void)
{
}

The following 4 functions provide the primitive start, stop, read and write sequences. All I2C transactions can be built up from these.
void i2c_start(void)
{
SDA = 1;             // i2c start bit sequence
i2c_dly();
SCL = 1;
i2c_dly();
SDA = 0;
i2c_dly();
SCL = 0;
i2c_dly();
}

void i2c_stop(void)
{
SDA = 0;             // i2c stop bit sequence
i2c_dly();
SCL = 1;
i2c_dly();
SDA = 1;
i2c_dly();
}

unsigned char i2c_rx(char ack)
{
char x, d=0;
SDA = 1;
for(x=0; x<8; x++) {
d <<= 1;
do {
SCL = 1;
}
while(SCL_IN==0);    // wait for any SCL clock stretching
i2c_dly();
if(SDA_IN) d |= 1;
SCL = 0;
}
if(ack) SDA = 0;
else SDA = 1;
SCL = 1;
i2c_dly();             // send (N)ACK bit
SCL = 0;
SDA = 1;
return d;
}

bit i2c_tx(unsigned char d)
{
char x;
static bit b;
for(x=8; x; x–) {
if(d&0x80) SDA = 1;
else SDA = 0;
SCL = 1;
d <<= 1;
SCL = 0;
}
SDA = 1;
SCL = 1;
i2c_dly();
b = SDA_IN;          // possible ACK bit
SCL = 0;
return b;
}

The 4 primitive functions above can easily be put together to form complete I2C transactions. Here’s and example to start an SRF08 ranging in cm:

i2c_start();              // send start sequence
i2c_tx(0xE0);             // SRF08 I2C address with R/W bit clear

i2c_tx(0x00);             // SRF08 command register address
i2c_tx(0x51);             // command to start ranging in cm
i2c_stop();               // send stop sequence

Now after waiting 65mS for the ranging to complete (I’ve left that to you) the following example shows how to read the light sensor value from register 1 and the range result from registers 2 & 3.

i2c_start();              // send start sequence
i2c_tx(0xE0);             // SRF08 I2C address with R/W bit clear

i2c_tx(0x01);             // SRF08 light sensor register address
i2c_start();              // send a restart sequence
i2c_tx(0xE1);             // SRF08 I2C address with R/W bit set

lightsensor = i2c_rx(1);  // get light sensor and send acknowledge. Internal register address will increment automatically.
rangehigh = i2c_rx(1);    // get the high byte of the range and send acknowledge.
rangelow = i2c_rx(0);     // get low byte of the range – note we don’t acknowledge the last byte.
i2c_stop();               // send stop sequence

I2C pada CodeVisionAVR

Create New Project

Klik OK.

Jika ada pertanyaan “Do you want to use the CodeWizardAVR?”, klik Yes. Lalu pilih type dari avr yang digunakan dan klik OK. Setelah itu, aturlah konfigurasi dari mikrokontroler yang digunakan. Lalu klik pada menu I2C untuk mengatur fitur I2C yang akan digunakan. Cobalah konfigurasi seperti gambar di bawah ini.

Setelah itu “Generate, Save and Exit” yang dipilih pada menubar CodeWizardAVR – Program. Jika pada CVAVR versi lama, hal itu terdapat pada menubar file.

Setelah setting dari CodeWizardAVR selesai, maka program sudah mulai bisa diedit.

Berikut sintax Master yang bisa digunakan untuk berkomunikasi dengan perangkat Slave pada komunikasi I2C.

//mengirim data I2C
i2c_start();

i2c_write(Device_ADDRESS);

i2c_write(address);

i2c_write(data);

i2c_stop();

/* 10ms delay untuk memastikan proses pengiriman data sudah selesai */

delay_ms(10);

-Device_ADDRESS adalah alamat dari perangkat slave I2C.

-address adalah alamat dari register yang akan dituliskan data.

-data 8-bits.

//menerima data I2C

i2c_start();

i2c_write(Device_ADDRESS);

i2c_write(address);

i2c_start();

i2c_write(Device_ADDRESS | 1);

data=i2c_read(0);

i2c_stop();

-Device_ADDRESS adalah alamat dari perangkat slave I2C.

-address adalah alamat dari register yang akan diakses.

-i2c_write(Device_ADDRESS | 1); Bit terakhir di or dengan 1 yang hasilnya pasti bit terakhir 1 berarti perintah menulis.

-data 8-bits dari slave dimasukan ke variable data.

Biasanya format pengiriman data I2C tergantung pada perangkat yang diakses yang dijelaskan terlebih dahulu pada datasheet.

Berikut contoh komunikasi I2C pada SPC MOTOR CONTROLLER.

i2c_start();        // Start Condition

i2c_write(0xE0);    // Tulis ke modul SPC MOTOR CONTROLLER

i2c_write(0x0E);    // Perintah “Set PWM”

i2c_write(0x01);    // Untuk Motor DC ke-2

i2c_write(128);     // Level PWM

i2c_stop();         // Stop Condition

delay_us(10);       // delay 10 us

i2c_start();        // Start Condition

i2c_write(0xE1);    // Baca ke modul SPC MOTOR CONTROLLER

temp1 = i2c_read(0);// Data Acknowledgement

i2c_stop();         // Stop Condition

___________________________________________________________

Berikut website yang membahas tentang I2C:

https://ccrma.stanford.edu/courses/250a-fall-2003/docs/avrlib-new/i2c_8c.html

http://www.engineersgarage.com/embedded/avr-microcontroller-projects/atmega32-twi-two-wire-interface

The I2C Physical Protocol
When the master (your controller) wishes to talk to a slave (our CMPS03 for example) it begins by issuing a start sequence on the I2C bus. A start sequence is one of two special sequences defined for the I2C bus, the other being the stop sequence. The start sequence and stop sequence are special in that these are the only places where the SDA (data line) is allowed to change while the SCL (clock line) is high. When data is being transferred, SDA must remain stable and not change whilst SCL is high. The start and stop sequences mark the beginning and end of a transaction with the slave device.

MPP Set : Software dan Hardware Pemutar Musik Monophonic

http://www.dailymotion.com/video/xiiabt_mpp-set-clip_tech

MonoPhonicPlayer (MPPlayer)

MonoPhonicPlayer adalah software yang digunakan untuk membuat atau memainkan file .mpp, file yang memainkan music monophonic. .mpp sendiri di buat dengan menggunakan format kode nokia composer. Software ini berbasis java jadi terlebih dahulu harus menginstall JDK (Java Development Kit) agar bisa di-running di PC. Berikut link untuk mendownload file JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html.

MPProgrammer (MPProgrammer)

MPProgrammer adalah software yang digunakan untuk membuat atau mendownload file .mpp ke MPP-Box via serialport. Sama seperti aplikasi di atas, MPProgrammer menggunakan format kode nokia composer.

MPP-Box (Hardware)

MPP-Box adalah perangkat yang memainkan musik monophonic yang terlebih dahulu didownload dari PC menggunakan MPProgrammer  via serialport.

Aplikasi

MPP set ini bisa digunakan sebagai bell di rumah atau sebagai klakson di sepeda atau di motor yang suaranya bisa diganti sesuai keinginan pengguna.

Berikut link untuk mendownload MPP Set http://www.mediafire.com/file/s9qotntbf284k0w/MPP%20set.rar. Isi file : aplikasi MPPlayer, MPProgrammer, MPP-Box (firmware MPP-Box.hex, file PCB Project Eagle format, dan readme.txt).

______________________________________________

Sample Code

Walls

4e1 8g1 4c1 8- 4a1 8c2 4f1 8- 8b1 8g1 8a1 8b1 8d2 8c2

Creed-Higher

16d2 16d2 8d2 16d2 8e2 16e2 16e2 8#f2 16#f2 16e2 16#f2 16#f2 16g2 16e2 16e2 8e2 16e2 8#f2 16#f2 32e2 32#f2 16d2 8e2 16e2 8#f2 8e2 16d2 8d2 16d2 4e2 16e2 8d2 16d2 16d2 16d2 8d2 16b1 16b1 16g2 8#f2 8#f2 16#f2 16e2 8#f2 16#f2 16e2 16d2 8d2 16d2 16d2

Warkop

8d1 8#d1 8- 8e1 8f1 2- 8g1 8#g1 2- 8e1 8f1 8-8g1 8#g1 8- 8#c2 8c2 8- 8f1 8#g1 8- 8c2 1b1 16- 16#a1 16#g1 8f1 8- 8#d1 8f1

Java s0ng
4g1 4b1 4c2 4- 4c2 8- 8e2 4f2 4g2 4f2 4e2 4c2 8- 32b2 32b3 16- 32c3 32c3 32c3 16- 32b2 32b3 16- 32g2 32g2 16- 32g2 32b3 16- 32c3 32c3 4- 4c2 4b1 4g1 4f1 4- 4f1 8- 8e1 4f1 4e1 4g1 4f1 2e1 8-

file .mpp yang dapat didownload. http://www.mediafire.com/file/5y02w2190kb0cu2/tones.mpp.rar


link tentang library tone untuk avr http://wangready.wordpress.com/2011/06/17/library-bahasa-c-untuk-aplikasi-nada-monophonic-pada-mikrokontroler-avr-dengan-compiler-winavr/

file source http://www.mediafire.com/file/wu6z3dmn1ej6dbu/mppset.rar

Aplikasi Komunikasi Serial pada PC Menggunakan Visual C# 2010 / Express

Komunikasi serial pada PC masih sering digunakan untuk beberapa aplikasi yang membutuhkan koneksi dengan mikrokontroler. Mikrokontroler yang mempunyai USART dapat terkoneksi dengan port serial pada PC dengan konektor DB9 dengan menggunakan RS232 standard . Jika menggunakan mikrokontroler avr, maka bisa lihat page berikut http://wangready.wordpress.com/2011/02/02/pemrograman-usart-pada-mikrokontroler-avr-avr-studio-4/ untuk pemrograman menggunakan AVR Studio 4. Berikut perancangan software untuk komunikasi serial dengan mode UART.

Pertama buka aplikasi Visual C# 2010. Kemudian, pilih new project. Lalu pilih lagi Windows Forms Aplication dan ketikan nama project pada bagian bawah form lalu OK. Lalu setelah itu buatlah Form seperti di bawah ini dengan terlebih daulu double click pada Form1.cs pada panel Solution Explorer sebelah kanan agar muncul template dari form tersebut.

Setelah selesai membuat form seperti di atas, perhatikan nilai property pada setiap komponen.

Control

Property

Value

Form1

Text

“Komunikasi serial”

Form1

AcceptButton

btnSend

lblMessage

BorderStyle

FixedSingle

txtDataReceived

ScrollBars

Vertical

txtDataReceived

MultiLine

True

txtDataToSend

MultiLine

True

Setelah itu klik Toolbox yang biasanya ada di sebelah kiri. Lalu pada sub Components klik SerialPort dan klik kembali pada form yang tampil untuk menambahkan komponen SerialPort pada form yang sedang kita buat. Setelah itu ganti nama serialPort1 dengan serialPort sebagai nama yang akan kita gunakan pada panel Properties.

Setelah selesai mengatur tampilan dari Form1, silakan fahami source code di bawah ini.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace serial
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
//—menset event handler untuk DataReceived event—
serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(DataReceived);
//—menampilkan nama serialport yang tersedia pada
// komputer—
string[] portNames = System.IO.Ports.SerialPort.GetPortNames();
for (int i = 0; i <= portNames.Length - 1; i++)
{
cbbCOMPorts.Items.Add(portNames[i]);
}
btnDisconnect.Enabled = false;
}

private void btnConnect_Click(object sender, EventArgs e)
{
//—menutup akses serialport apabila akses serialport terbuka—
if (serialPort.IsOpen)
{
serialPort.Close();
}
try
{
//—mengatur beberapa parameter untuk koneksi serial
// port—
serialPort.PortName = cbbCOMPorts.Text;
serialPort.BaudRate = 9600;
serialPort.Parity = System.IO.Ports.Parity.None;
serialPort.DataBits = 8;
serialPort.StopBits = System.IO.Ports.StopBits.One;
//—buka serial port—
serialPort.Open();
//—menampilkan status dari serial port dan
// enable/disable -kan tombol—
lblMessage.Text = cbbCOMPorts.Text + " connected.";
btnConnect.Enabled = false;
btnDisconnect.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void btnDisconnect_Click(object sender, EventArgs e)
{
try
{
//—tutup serial port—
serialPort.Close();
//—menampilkan status dari serial port dan
// enable/disable -kan tombol—
lblMessage.Text = serialPort.PortName +" disconnected.";
btnConnect.Enabled = true;
btnDisconnect.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void btnSend_Click(object sender, EventArgs e)
{
try
{
//—menulis tipe data string pada serial port—
serialPort.Write(txtDataToSend.Text + Environment.NewLine);
//—menambahkan string yang telah dikirim pada TextBox control—
txtDataReceived.AppendText(">" + txtDataToSend.Text +  Environment.NewLine);
txtDataReceived.ScrollToCaret();
//—bersihkanTextBox control—
txtDataToSend.Text = string.Empty;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

//—Event handler untuk DataReceived event—
private void DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
//—memanggil delegasi untuk mengambil data yang diterima—
txtDataReceived.BeginInvoke(new myDelegate(updateTextBox));
}

//—Delegate and subroutine untuk ditampilkan pada TextBox control—
public delegate void myDelegate();
public void updateTextBox()
{
//—menambahkan data pada TextBox control—
txtDataReceived.AppendText(serialPort.ReadExisting());
txtDataReceived.ScrollToCaret();
}
}
}

Setelah program jadi dan tidak terdapat pesan pada Error List yang terdapat pada bagian bawah panel kerja, maka program bisa di debug. Klik tombol Start Debugging atau tekan F5.

Setelah berhasil di debug, maka program bisa langsung di-publish untuk menghasilkan setup.exe. Klik kanan pada nama project yang ada pada panel Solution Explorer dan klik properties. Lalu pilih menu Publish dan setting juga Publish Location sesuai keinginan. Lalu klik Publish Wizard… untuk melakukan settingan terlebih dahulu atau Publish Now untuk publish langsung.

Berikut link demo aplikasi komunikasi serial di atas :  files.indowebster.com/download/files/ser_file_app

Berikut link download project :  files.indowebster.com/download/files/ser_code

Daftar Pustaka:

Lee, Wei-Meng[2007].”Practical .NET 2.0 Networking Projects”. Apress, New York, USA.

Control

Property

Value

Form1

Text

“Komunikasi serial”

Form1

AcceptButton

btnSend

lblMessage

BorderStyle

FixedSingle

txtDataReceived

ScrollBars

Vertical

txtDataReceived

MultiLine

True

txtDataToSend

MultiLine

True

Follow

Get every new post delivered to your Inbox.