Komunikasi Serial Mikrokontroler Software Programs. The use of field-programmable devices on a micro controller may allow field update of the or permit late.
hai gaes....lama tak posting nih, kemarin sudah posting tentang komunikasi dengan i2c silahkan baca kalau yang belum mengerti disini .nah sekarang kita akan bahas mengenai komuniakasi serial atmega 32. dalam ttorial kali ini menggunakan 2 buah atmega 32 .
langsung saja kita buka pertama software proteusnya dan cari komponen dibawah ini:
setelah memilih komponen tersebut maka kita buat rangkaian seperti dibawah ini untuk transmitternya (pengirim ):
setelah berhasil dengan transmitter kita buat rangkaian receivernya atau penerimannya :
jika keduanya digabung maka akan tampak seperti dibawah ini.. ingat RX transmiter bertemu Tx receiver dan begituula sebaliknya.
setelah selesai mari kita buka codevision avrnya bro...
buat project seperti postingan sebelumnya dan setting bagian uart untuk transmitter sebagai berikut :
setelah selesai generate save dan exit ya..trus kita program seperti dibawah ini:
#include <mega32.h>
#include <delay.h>
#include <stdio.h>
#include <stdlib.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
// Standard Input/Output functions
#include <stdio.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x20
// Read the 8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)0);
ADCSRA|=0x10;
return ADCH;
}
// Declare your global variables here
int a,b,c;
char ag[20];
void rutin(void)
{
while(1)
{
a=150;
b=200;
c=50;
if(PINB.00&&PINB.11&&PINB.21)
{
lcd_clear();
lcd_gotoxy(0,1);
sprintf(ag, '%d',a);
lcd_puts(ag);
putchar (a);
}
![Komunikasi Serial Mikrokontroler Software Update Komunikasi Serial Mikrokontroler Software Update](https://fahmizaleeits.files.wordpress.com/2010/05/komunikasi-serial-dengan-simulasi-proteus.jpg?w=429&h=291)
if(PINB.01&&PINB.10&&PINB.21)
{
lcd_clear();
lcd_gotoxy(0,1);
sprintf(ag, '%d',b);
lcd_puts(ag);
putchar(b);
}
if(PINB.01&&PINB.11&&PINB.20)
{
lcd_clear();
lcd_gotoxy(0,1);
sprintf(ag, '%d',c);
lcd_puts(ag);
putchar(c);
}
}
}
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=0xFF;
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: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B 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
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
![Serial Serial](http://slideplayer.com/1953186/7/images/2/Silabus+Arsitektur+Mikroprosesor+CPU+Bus+mikroprosesor.jpg)
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 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;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x4D;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 750.000 kHz
// ADC Voltage Reference: AREF pin
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
// LCD module initialization
lcd_init(16);
while (1)
{
// Place your code here
rutin();
};
}
sekarang kita buat program file baru untuk penerimannya.. yaitu sebagai berikut settingnya :
save generate dan exit ya, setelah itu program seperti dibawah ini :
#include <mega32.h>
#include <delay.h>
#include <stdlib.h>
#include <stdio.h>
char data;
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#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)
// USART Receiver buffer
#define RX_BUFFER_SIZE 2
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
int data1, data2, data3, data4, data5;
interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,data;
status=UCSRA;
data=UDR;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))0)
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))0)
{
if(data 0 )rx_wr_index=0;
else
{
rx_buffer[rx_wr_index++]=data;
data1 = rx_buffer[0]; //
data2 = rx_buffer[1]; //
// data3 = rx_buffer[2];
// data4 = rx_buffer[3];
// data5 = rx_buffer[4]; //
if (rx_wr_index RX_BUFFER_SIZE) rx_wr_index=0;
}
}
}
#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART Receiver buffer---
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter0);
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
int b;
char screen[20];
void tampil(void)
{
lcd_clear();
lcd_gotoxy(3,0);
sprintf(screen, 'TEST');
lcd_puts(screen);
lcd_gotoxy(0,1);
sprintf(screen, '%3d', data1);
lcd_puts(screen);
lcd_gotoxy(4,1);
sprintf(screen, '%3d', data2);
lcd_puts(screen);
lcd_gotoxy(4,3);
}
void gabung_data()
{
int a;
a=data1<<8;
b=a|data2;
tampil();
}
void rutine(void)
{
gabung_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=0xFF;
// 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: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B 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
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: Timer 2 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;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: Off
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x90;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x4D;
// 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);
// Global enable interrupts
#asm('sei')
while (1)
{
rutine();
};
}
build juga file tersebut
setelah itu buka kembali file proteusnya. dan masukan HEX dikedua mikrokontroller setelah itu jalankan program simulasi pada proteus dan hasilnya sebagai berikut :
ini adalah tampilan awal sebelum tombol di tekan :
setelah tombol satu ditekan maka mikrokontroller pengirim akan mengirimkan data bernilai 150 dan mikrokontroler b akan menerima dan menampilkannya di LCD
untuk tombol B maka nilai yang dikirim bernilai 200:
selesai deh tutorial kali ini, program dapat dikembangkan sendiri ya :)COM port is not dead. It is virtual!
What is it?
Terminal is a simple serial port (COM) terminalemulation program. It can be used for communication with differentdevices such as modems, routers, embedded uC systems, GSM phones, GPS modules... Itis very useful debugging tool for serial communication applications.
Features
- without installation, only single and small .exe file ~300KB
- simple file send
- Rx and Tx characters counter
- baudrate up to 256kbps & custom baudrate
- up to 64 COM ports
- log to file (hex & string)
- 24 custom transmit macros with auto repeat function
- scripting (with graph/visualization support)
- remote control over TCP/IP - telnet
- run applications from macro commands
- open www sites from macro commands
- request/response macros
- CSV Graph - As a little 2012 New Year's Gift ;)
- 4th/black graph and scale factors for CSV values
- auto scroll checkbox - to prevent auto scrolling
- WriteToFile() procedure in scripting
- %SCRS'script.tsc' and %SCRE commands for macros - check help
- offset for %SUM and %XOR macro commands
- time stamp, scale factors and offsets for CSV graph
- Quit() function in scripting
- parameter/argument to open script file at start up
- Tx char delay strategy changed (real zero delay if value=0)
- hot key changes: DEL=RXClear, ESC=send code 27
- flush buffers on disconnect to avoid 'not responding'
- NEW: macro up to 256 characters
- FIX: lost chars problem...better but not fixed
- FIX: ComSetDTR,ComSetRTS,...LED turn on/off bug
!!! If you have problems with new version you can still download older releases on the bottom of the page !!!
Macros
In macros you can use all characters from keyboard and any ASCIIchar if you use $xx or #xxx. Where $xx is hex and #xxx dec format ofascii code. If you want to use # or $ char in macro you should type ittwice ($$=$ and ##=#).To calculate XOR checksum byte use %XORxx command. To calculate SUM (1byte sum) checksum byte use %SUMxx command. Where xx is offset of first byte for calculation.
To insert delay in macro string use %DLYxxxx, where xxxx is value 0000-9999 in ms.
To insert delay in macro string use %DLYxxxx, where xxxx is value 0000-9999 in ms.
You can store macro in macro file. Active macro is'saved' even if you don't save it and will be available next time whenyou'll start Terminal. Macro string can be up to 256 characters long.
some examples:
X1##Y2##Z3##$0D$0A - this will send 'X1#Y2#Z3#'CR'LF'
ABC%DLY1000DEF - this will send ABC and after ~1000ms DEF
%RUN'cmd.exe' - this will run command line prompt
%URL'http://www.google.com' - guess what?! ;)
%M03 - this will send/run macro #3 (there are some limits when using this)
%LOGS - start logging
%LOGE - stop logging
%SCRS'script.tsc' - load and start script
Scripting
Simple pascal syntax scripting is possible. You can write short scripts to do some simple tasks. More about supported command you can find if you click 'Help' button.Below in attachment section you can find few sample scripts to check and test functionality.
TCP/IP remote control
Terminal can also act like telnet server and listen on selected TCP port. You can connect to it with any telnet client program from another computer in network (or over internet from different location) and see what's going on in terminal and send commands etc.Download & Links
Download new version of the Terminal software - version 1.93b 20141030
Terminalis still FREE but if you find this tool useful and if you'd like tosupport this project and make a small donation...here is the simplestway to do it. It's secure, quick and easy. Thank you!