Dasar teori :
Skematik simulasi :
Code RX bit banging, PIN RX digunakan PINA.0 :
Test code dengan mengirim data (TX):
- http://en.wikipedia.org/wiki/Bit_banging
- http://www.brouhaha.com/~eric/pic/bitbanging.htm
Skematik simulasi :
Code RX bit banging, PIN RX digunakan PINA.0 :
#include <mega32.h> #include <delay.h> #include <alcd.h> #define baud 9600 // 9600,8,N,1
#define RXPIN PINA.0 #define DDR_RXPIN DDRA.0 #define PORT_RXPIN PORTA.0 #define delay_baudrate 1000000/9600 #define usart_delay delay_baudrate unsigned char get_usart_data(){ unsigned char usartdata=0;//,i=0; DDR_RXPIN=0; // set input PORT_RXPIN=1; // Pull up while(RXPIN); delay_us(usart_delay); usartdata |= RXPIN <<0 ; delay_us(usart_delay); usartdata |= RXPIN <<1 ; delay_us(usart_delay); usartdata |= RXPIN <<2 ; delay_us(usart_delay); usartdata |= RXPIN <<3 ; delay_us(usart_delay); usartdata |= RXPIN <<4 ; delay_us(usart_delay); usartdata |= RXPIN <<5 ; delay_us(usart_delay); usartdata |= RXPIN <<6 ; delay_us(usart_delay); usartdata |= RXPIN <<7 ; delay_us(usart_delay); return usartdata; } unsigned char buff[50]; void main(void) { int i; lcd_init(16); while (1) { lcd_gotoxy(0,0); for(i=0;i<32;i++){ buff[i]=get_usart_data(); } for(i=0;i<32;i++){ lcd_putchar(buff[i]); } }; }
Test code dengan mengirim data (TX):
#include <mega32.h> // Alphanumeric LCD functions #include <alcd.h> // Standard Input/Output functions #include <stdio.h> // Declare your global variables here #include <delay.h> void main(void) { unsigned char i=0; // 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=0x18; UCSRC=0x86; UBRRH=0x00; UBRRL=0x67; lcd_init(16); lcd_gotoxy(0,0); lcd_putsf("TRANSMITTER"); while (1) { printf("hallo 1234567890USART BIT BANGED"); delay_ms(200); printf("Clear "); delay_ms(200); printf("Sh Mukti ->USART RX BIT BANGING "); delay_ms(200); printf("Clear lagi %3d",i); delay_ms(200); i++; } }
download project and simulation
1 comment:
kang mukti memnag juara deh.. sangat membantu, jazakallah khoir ^_^
Post a Comment