Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
SMART CAR

SMART CAR

Ratings: (0)|Views: 62|Likes:
Published by PRASATH.R
car
car

More info:

Published by: PRASATH.R on Mar 05, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

03/10/2011

pdf

text

original

 
PROGRAMMING NOTES
INCLUDE FILES:
#include <hidef.h>#include "derivative.h"
USART GLOBAL FUNCTION DECLARATIONS:
void uart0_9600_init(void);unsigned char uart0_rx(void);void uart0_tx(unsigned char a);void uart0_tx_string(char *s) ;void uart0_tx_number(unsigned char a);void uart0_tx_int(unsigned int a);void uart0_tx_newline(void);
FUNCTION DEFINITIONS:void uart0_9600_init(void)//INITIALISE THE BAUD RATE
{SCI0BDL=13;SCI0CR1=0;SCI0CR2=12;}
void uart0_tx_int(unsigned int a) //TRANSMITS AN INTEGER
{unsigned int temp;temp=a/10000;uart0_tx (temp + 0x30);a=a-temp*10000;temp=a/1000;uart0_tx(temp + 0x30);a=a-temp*1000;temp=a/100;uart0_tx(temp + 0x30);a=a-temp*100;temp=a/10;uart0_tx(temp + 0x30);a=a-temp*10;uart0_tx(a + 0x30);}
 
void uart0_tx_number(unsigned char a) //TRANSMITS AN ALPHABET
{unsigned char temp;temp=a/100;uart0_tx(temp + 0x30);a=a-temp*100;temp=a/10;uart0_tx(temp + 0x30);a=a-temp*10;uart0_tx(a + 0x30);}
void uart0_tx_string (char *s) //TRANMITS A STRING
{while (*s){uart0_tx(*s);s++;}}
void uart0_tx_newline(void) //NEW LINE FEEDING
{uart0_tx (0x0A);uart0_tx (0x0D);}
unsigned char uart0_rx (void) //RECEIVING INPUT FROM HYPERTERMINAL
{while(SCI0SR1_RDRF==0);return SCI0DRL;}
void uart0_tx(unsigned char a) //USED AS SUBROUTINE IN ALL TX FUNCTIONS
{SCI0DRL=a;while(SCI0SR1_TC==0);}
 
PARTS CONNECTED:LED CONTROL:
o
 
DDRT=0xF0;//
DATA DIRECTION CONTROL REGISTER FOR SETTING O/P PINS-4 TO 7 AS O/PPINS
o
 
PTT=0x0F; //0 TO TURN ON ALL LEDS CONNECTED IN 4 TO 7 PINS
o
 
PTT=0xFF; //Turning Off all LEDs
o
 
PTT_PTT4=0;//TURN ON FIRST LED1
o
 
PTT_PTT4=1;//TURN OFF FIRST LED1
o
 
uart0_tx(0x0D);//USE THIS FUNCTION BEFORE CALLING ANY UART FUNCTIONSSWITCH CONTROL:
o
 
DDRP_DDRP5=0; //Port P Pin 5 & 7 set to input
o
 
DDRP_DDRP7=0;
o
 
PERP_PERP5=1; //Port P Pin 5 & 7 Pull-up Enable
o
 
PERP_PERP7=1;
o
 
if(PTP_PTP5==0) ; //SWITCH PRESS CHECKING
o
 
for (cnt=0;cnt<=550000;cnt++); //MAXIMUM SWITCH DETECTION TIME
o
 
if(PTP_PTP7==0); //SWITCH PRESS CHECKINGDC MOTOR CONTROL:
o
 
DDRE_DDRE2=1; // Port E pin 2 & 3 set to output
o
 
DDRE_DDRE3=1;
o
 
DDRP_DDRP0=1; //PORT P PIN 0 & 1 AS OUTPUT
o
 
DDRP_DDRP1=1;
o
 
PORTE_PE2=0; //H BRIDGE ENABLE BY SUPPLY
o
 
PORTE_PE3=1;
o
 
PWMPOL_PPOL0=1; //PWM pulse High at beginning of Period
o
 
PWMPOL_PPOL1=1; //PWM pulse High at beginning of Period
o
 
PWMCLK_PCLK0=1; // clock SA as clock source for PWM
o
 
PWMCLK_PCLK1=1; // clock SB as clock source for PWM
o
 
PWMPRCLK =0x00; //PWM Prescale Clock Select-NO PRESCALAR-CLOCK A=CLOCK B=2MHZ
o
 
PWMSCLA =5; //PWM SCALE A REG clock SA = clock A / (2 * 5) = 200KHz
o
 
PWMSCLB =5; //PWM SCALE B REG clock SB = clock B / (2 * 5) = 200KHz
o
 
PWMPER0 = 200; // PWM Channel Period 0 Register PWM Period 1KHz
o
 
PWMPER1 = 200; // PWM Channel Period 1 Register PWM Period 1KHz
o
 
PWMDTY0 = 50; //
 
PWM Channel Duty 0 Register H BRIDGE CONTROL
o
 
PWMDTY1 = 0; //
 
PWM Channel Duty 0 Register H BRIDGE CONTROL
o
 
PWME_PWME0=1; //PWM channel 0 Enable
o
 
PWME_PWME1=1; //PWM channel 1 Enable, NOW MOTOR STARTS
o
 
PORTE_PE2=0; //H BRIDGE DISABLES BY SAME POLARITY SUPPLY
o
 
PORTE_PE3=0;
o
 
PWMDTY0 = 50; //H BRIDGE CONTROL FET FORWARD DIRECTION
o
 
PWMDTY1 = 0;
o
 
PWMDTY0 = 0; //H BRIDGE CONTROL FET REVERSE DIRECTION

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->