0% found this document useful (0 votes)
93 views3 pages

Serial Communication Atm8

This code introduces serial communication using an ATmega8 microcontroller. It configures the USART module to operate asynchronously at 9600 baud with 8-bit data, 1 stop bit, and no parity. The code provides a menu-driven user interface over a serial connection that displays any character received.

Uploaded by

armando carpas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views3 pages

Serial Communication Atm8

This code introduces serial communication using an ATmega8 microcontroller. It configures the USART module to operate asynchronously at 9600 baud with 8-bit data, 1 stop bit, and no parity. The code provides a menu-driven user interface over a serial connection that displays any character received.

Uploaded by

armando carpas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

/*******************************************************************************

SERIAL COMMUNICATION ATM8


This source code introduces you to the working of the USART Module
available in ATMEGA 8 @8MHz system clock.
This code does the task of preparing a menu driven user interface on
hyperterminal using the USART Module.
Here the USART Module is configured to operate in the Asychronous
mode. With a Frame format of 8-bit Data with 1 stop bit and no parity
bit the baud rate is fixed for 9600 bps.
***********************************ELECDUDE.COM*********************************/

#define F_CPU 8000000UL

//Define the MPU operating frequency

#include <avr/io.h>
//Header file for AVR device specific I/O Definitions.
#include <avr/interrupt.h>
//Header file for incorportaing interrupt handling faclity (not used here).
#include <util/delay.h>
//Header file for incorporating delay routines.
#include <avr/pgmspace.h>
//Header file for incorporating Program space string utilities.
#include <stdlib.h>
//ISO Standard library of C functions and macros.
#include "USART.h"
//Defines C functions for accessing USART Module.

#define BIT(x)
(1 << (x)) //Set a particular bit mask
#define CHECKBIT(x,b) (x&b)
//Checks bit status
#define SETBIT(x,b) x|=b;
//Sets the particular bit
#define CLEARBIT(x,b) x&=~b;
//Sets the particular bit
#define TOGGLEBIT(x,b) x^=b;
//Toggles the particular bit
void WaitMs(unsigned int ms);
void welcome_screen(void);
int main()
{
unsigned int ch;
uart_init(9600);

//Initialise the USART Module with the given Baudrate and


//Frame format.
uart_puts_P("\r\n\t************************************************ ");
uart_puts_P("\r\n\t
ATMEGA 8 DEVELOPMENT BOARD ");
uart_puts_P("\r\n\t************************************************ ");
uart_puts("\r\n\t\t ");
uart_puts_P("\rWelcome to ElecDude. Press any to display.....");
uart_puts("\r\r\r\r");
while(1) //Enter into a uncoditional while loop..
{
ch=uart_getc();
uart_puts("\n\n\t\t");
uart_putc('<');
uart_putc(ch);
uart_putc('>');
WaitMs(100);
}

return 0;
}

void setup()
{
DDRB |= (1<<1) | (1<<2) | (1<<3) | (1<<5) ; // BLANK, SS, MOSI, SCLK as OUTPUTS
DDRD |= (1<<3) | (1<<4) | (1<<6) | (1<<7) ; // VPRG, XLAT, GSCLK, Debug as OUTPUTS
DDRC = 255;
XLAT_Low;
BLANK_High;
VPRG_Low;
Debug_Low;
//Timer 1 (16bit)
TCCR1A = (1<<WGM11) | (0<<WGM10);

// Fast PWM with ICR1 as top

TCCR1B = (1<<WGM13) | (1<<WGM12);

// Fast PWM with ICR1 as top

TCCR1B |= (1<<CS12) | (1<<CS11) | (1<<CS10); // external clock (T1) on rising egde


TIMSK1 |= (1<<TOIE1);
ICR1

= Gray_Scale_Depth;

// enable overflow interupt


// Grey scale depth for TLC-PW

//Timer 0 (8bit)
TCCR0A = (1<<WGM01) | (0<<WGM00);

// CTC

TCCR0A |= (0<<COM0A1) | (1<<COM0A0);

// Toggle on Compare Match

TCCR0B = (0<<CS02) | (0<<CS01) | (1<<CS00); // No Prescaler


OCR0A = 0;

// f(OCR) = F_CPU/2/Prescaler

//UART Initialisation
UCSR0A |= (1<<U2X0);

// Double up UART

UCSR0B |= (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);

// UART RX, TX und RX Interrupt enable

UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00)

// Asynchrous 8N1

UBRR0H = 0;
UBRR0L = 1; //Baud Rate 1 MBit --> 0% Error at 16MHz
//Enable global interrupts
sei();
//Configure SPI
SPCR = (1<<SPE)|(1<<MSTR);
SPSR = B00000000;
ptr=display_buffer;
}

You might also like