Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //**************************************************************
- //******** FUNCTIONS FOR SERIAL COMMUNICATION USING UART *******
- //**************************************************************
- //Controller: ATmega168 (Clock: 8 Mhz-internal)
- //Compiler: AVR-GCC
- //Version : 2.0
- //Author: CC Dharmani, Chennai (India)
- // www.dharmanitech.com
- //Date: 26 Feb 2009
- //**************************************************************
- //**************************************************
- // ***** SOURCE FILE : UART_routines.c ******
- //**************************************************
- #include "UART_routines.h"
- #include <avr/io.h>
- #include <avr/pgmspace.h>
- //**************************************************
- //Function to receive a single byte
- //*************************************************
- unsigned char receiveByte( void )
- {
- unsigned char data, status;
- while(!(UCSR0A & (1<<RXC0))); // Wait for incomming data
- status = UCSR0A;
- data = UDR0;
- return(data);
- }
- //***************************************************
- //Function to transmit a single byte
- //***************************************************
- void transmitByte( unsigned char data )
- {
- while ( !(UCSR0A & (1<<UDRE0)) ); // Wait for empty transmit buffer
- UDR0 = data; //Start transmition
- }
- //***************************************************
- //Function to transmit hex format data
- //first argument indicates type: CHAR, INT or LONG
- //Second argument is the data to be displayed
- //***************************************************
- /*void transmitHex( unsigned char dataType, unsigned long data )
- {
- unsigned char count, i, temp;
- unsigned char dataString[] = "0x ";
- if (dataType == CHAR) count = 2;
- if (dataType == INT) count = 4;
- if (dataType == LONG) count = 8;
- for(i=count; i>0; i--)
- {
- temp = data % 16;
- if((temp>=0) && (temp<10)) dataString [i+1] = temp + 0x30;
- else dataString [i+1] = (temp - 10) + 0x41;
- data = data/16;
- }
- transmitString (dataString);
- }
- */
- //***************************************************
- //Function to transmit a string in Flash
- //***************************************************
- void transmitString_F(char* string)
- {
- while (pgm_read_byte(&(*string)))
- transmitByte(pgm_read_byte(&(*string++)));
- }
- //***************************************************
- //Function to transmit a string in RAM
- //***************************************************
- void transmitString(unsigned char* string)
- {
- while (*string)
- transmitByte(*string++);
- }
- //************ END ***** www.dharmanitech.com *******
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement