You are on page 1of 28

Yantrik Automation

www.yantrik.in

Y A Development Board
Version- Ya1.01

User Manual www.yantrik.in

The Yantrik Automation Development Board is a handy, battery-powered microcontroller based board which is very ideal for personal, educational and research projects. Based on the Atmel ATmega8535/16/32 microcontroller, the Yantrik Automation Development Board includes 8/16/32K of FlashRAM, outputs for four DC motors or two stepper motors, inputs for a large variety of analog and digital sensors, and a 16*2 alphanumeric LCD screen and also supports computer communication using MAX232 IC. The Yantrik Automation Development Board runs BASCOM-AVR, a cross-platform, specialized AVR version of the BASIC programming language. It also supports the embedded C compiler for controllers of AVR family.

Copyright 2010: Yantrik Automation 1

Yantrik Automation
www.yantrik.in

Contents
Section Name 1. Specifications and Feature 2. Ports and Connector Details 3. Quick Start 4. Programming in BASIC language 5. Precautions 6. Troubleshooting

1. Specifications and Features


The YA Development Board Features are: 40 Pin Atmel ATmega16/32 microcontroller with internal system clock upto 8 MHz and externally upto 16 MHz 16/32 KB FlashRAM memory for programs 1/2 KB of SRAM 512/1024 Bytes of EEPROM One 4x1 Pin SPI Relimate Header Eight 3x1 Pin Relimate header inputs for 8 analog sensors One 16 Pin header to connect 16*2 alphanumeric LCD Two onboard L293D drivers for motors 7805 Voltage regulator with heat sink Dual power input options (Through molex connector or through DC Jack)

Two programmable Micro-Switches Copyright 2010: Yantrik Automation 2

Yantrik Automation
www.yantrik.in Programmable LEDs Two DPDT switches (one for power on/off and one for reset) MAX 232 Level converter for RS232 communication One 3x1 Pin relimate header for RS2332 communication Four 8 Pin bergistick headers (male) from each port of ATmega16/32 Wide input power range from 7 volts to 12 volts at 0.5-2 Amps

2. Ports and Connectors Details


Here is the detailed information of the Yantrik Automation Development Board Power Switch, 7805 and Power Connector: Power Switch is used to turn on the power supply of the board. Power will flow to voltage regulators only when the power switch is in down position. 7805 Voltage regulators will regulate the power supply to 5 volts. 7805 will work only when the input power is at least 7 volts. Power supply can be given either through the Power Connector or through the DC Jack. Be sure to use ONLY ONE power source.

Regulated 5 Volts Power Output: This connector can be used to provide power to any external device. Taking into consideration, that the board can only withdraw power up to 2 Amps, power output from this jack may vary. Reset Switch: This switch is used to reset the program counter to zero and restart the program execution. In execution mode, Reset switch is needed to be kept in down position. While downloading the program to the chip, reset switch should be kept in up position

Copyright 2010: Yantrik Automation 3

Yantrik Automation
www.yantrik.in LEDs: Four LEDs are provided on the board for the testing purpose. These LEDs can be programmed to glow. Connection details of the LEDs and microcontroller pins are given below LED 1 LED 2 LED 3 LED 4 : : : : PortC.4 PortC.5 PortC.6 PortD.7

Each individual LED can be programmed to glow or to blink by programming the corresponding microcontroller pin. Programmable Micro-Switches: These switches are connected with microcontroller and can be used as input device to the microcontroller. These switches can be used for testing purpose. Connection details of these pins are given below T1 T2 : : PortD.2 PortD.3

When these switches are pressed, they actually short the corresponding microcontroller pin with GND, so it is required to use internal pull up registers to use these switches as input device. 40 Pin Base for microcontroller: This base is provided to install and remove microcontroller chip easily. This board supports ONLY two microcontrollers Atmel ATmega16 and Atmel ATmega32. Both microcontrollers have exactly same pin configuration but they differ in terms of the memory. For more information on microcontroller, refer to the respective datasheet. 16 Pin Base for L293D Driver ICs: There are two bases provided onboard to use L293D H-Bridge with microcontroller. This board supports ONLY L293D Driver. No other H-Bridge IC can be installed instead of L293D. For more information on L293D, refer to its datasheet. Motor Connectors: The YA Development Boards four DC motor outputs are located bottom left side of the board by means of molex connectors. These connectors can also be used to drive two stepper motors. These connectors have following configuration Copyright 2010: Yantrik Automation 4

Yantrik Automation
www.yantrik.in TERMINAL-1 For Connector 1(left) PWM Channel Direction Bit For Connector 2(left) PWM Channel Direction Bit TERMINAL-2 For Connector 1(left) PWM Channel Direction Bit For Connector 2(right) PWM Channel Direction Bit

= PortD.2 = PortC.6 = PortD.3 = PortC.7

= Pwm1B = PortD.6 = Pwm1A = PortD.7

Eight 3 Pin Headers for Sensors: This board provides capability to connect upto eight sensors directly to ADC port of the ATmega16/32. ADC need to be configured and started while working with Analog sensors whereas ADC need to kept off while working with Digital sensor with same Port A. However types of sensors can be used at a time but they both should be different ports, i.e. analog sensors should be on Port A (with ADC started) and digital sensors should be on any other port (with that port in input mode). Given below is the connection details of all eight headers with corresponding microcontroller pin ADC(0) ADC(1) ADC(2) ADC(3) ADC(4) ADC(5) ADC(6) ADC(7) = = = = = = = = PortA.0 PortA.1 PortA.2 PortA.3 PortA.4 PortA.5 PortA.6 PortA.7

Copyright 2010: Yantrik Automation 5

Yantrik Automation
www.yantrik.in RS232 Connector: This connector is provided for RS232 communication. Pin configuration of RS232 is given below RX TX = = PortD.0 PortD.1

16 Pin LCD Header: A 16 Pin header is provided to interface one 16 * 2 Alphanumeric LCD. Given below are the pin configuration details Lcdpin = Pin Db4 = Portb.4 Db5 = Portb.5 Db6 = Portb.6 Db7 = Portb.7 E = Portb.3 Rs = Portb.2 DB4 to DB7: Data Buses of LCD E: Enable pin of LCD Rs: Register Select of LCD These pin configuration are only for the LCD which is 16 * 2 alphanumeric display. For other type of LCD this may vary. Refer to related datasheet of the LCD incase if you are using a different one.

2.

Quick Start

Here are the steps to getting started with The YA Development Board Connect the power supply to power terminal of the board. Connect the USB cable on USB header on the board and connect it at USB port of the host computer. Install the drivers of the ISP USB cable Copyright 2010: Yantrik Automation 6

Yantrik Automation
www.yantrik.in Keep the reset button at down position and switch on the power button. The board is now ready to download the program from the computer, make sure that power is coming to the board and Power LED is glowing. Open AVRDUDE software and upload the HEX file generated by compiling the program in BascomAVR Software to Flash Option Click on Execute button Now, switch off the power button, disconnect the ISP cable, and change the reset button position. Switch on the power button to run your program.

Follow the above steps to burn and run the code on the YA Development Board.

4. Programming in BASIC Language using BASCOM-AVR and Sample codes


4.1 Overview BASCOM AVR is an IDE based development platform and is developed by MCS Electronics. BASCOM uses BASIC programming language. It is very easy to write, compile and download the program with BASCOM. 4.2 Basics To write program with Basic language for AVR, start with following syntax 1. Define $regfile instruct the compiler to use the specified register file.

Syntax $REGFILE = "name_of_file" Name_of_file - It refers to the name of register file. The register files are stored in the BASCOM-AVR application directory with .DAT extension.

Copyright 2010: Yantrik Automation 7

Yantrik Automation
www.yantrik.in The register file holds information about the chip such as the internal registers and interrupts addresses. Since we are using Atmega16 Microcontroller, we will define $regfile= 8535def.dat this file is loaded for Atmel atmega8535

Note: For Atmega32, we will define $regfile= m32def.dat 2. $crystal It defines the clock speed at which you want to run your microcontroller. Syntax $CRYSTAL = Value Value - A numeric constant defining the Frequency of the crystal. Example $crystal = 4000000 it set the clock speed at 4MHz 3. Config - The CONFIG statement is used to configure the various hardware devices and other features of microcontroller. We are required to configure the following hardware and features: a) LCD b) ADC c) Timer

(a) Configuring LCD BASCOM allows us to configure LCD with ease. You can configure various types of LCDs with BASCOM like 16*2, 16*4, 20*2, 20*4 OR 40*4 alphanumeric LCDs. The Lcd provided on the YA Controller Board is of size 16*2 i.e. 16 char in one line and total of 2 lines of display. Syntax for Configuring LCD: CONFIG LCD = LCD_type Copyright 2010: Yantrik Automation 8

Yantrik Automation
www.yantrik.in CONFIG LCDPIN = PIN, DB4= PN, DB5=PN, DB6=PN, DB7=PN, E=PN, RS=PN LCD_type It is the type of LCD you want to configure. It can be: 40 * 4,16 * 1, 16 * 2, 16 * 4, 16 * 4, 20 * 2 or 20 * 4 or 16 * 1a or 20*4A. Config Lcdpin - Override the LCD-PIN select options. To configure a 16*2 alphanumeric LCD of YA Development Board, the command is Config LCD = 16*2 Config lcdpin = pin, Db4 = Portb.4, Db5 = Portb.5, Db6 = Portb.6, Db7 = Portb.7, E = Portb.3, Rs = Portb.2 (b) Configuring ADC Syntax CONFIG ADC = single, PRESCALER = AUTO, REFERENCE = avcc ADC It defines the Running mode. Its value is SINGLE. PRESCALER - A numeric constant for the clock divider. Use AUTO to let the compiler generate the best value depending on the XTAL REFERENCE - Some chips like the M163 have additional reference options.Its value may be OFF, AVCC or INTERNAL. See the data sheets for the different modes. Configuring ADC in BASCOM is also very easy. To configure ADC in BASCOM, the statement is Config Adc = Single, Prescaler = Auto, Reference = Avcc Start ADC (C) Configuring Timers to generate PWM Syntax CONFIG TIMER1 = COUNTER | TIMER | PWM, Copyright 2010: Yantrik Automation 9

Yantrik Automation
www.yantrik.in PRESCALE= 1|8|64|256|1024, PWM = 8 | 9 |10, COMPARE A PWM = CLEAR UP| CLEAR DOWN | DISCONNECT COMPARE B PWM = CLEAR UP| CLEAR DOWN | DISCONNECT TIMER1: It is a 16 bit counter. PRESCALE - The TIMER is connected to the system clock in this case. You can select the division of the system clock with this parameter. Valid values are 1, 8, 64, 256 or 1024 PWM - Can be 8, 9 or 10. COMPARE A (B) PWM It refers to PWM compare mode. It can be CLEAR UP or CLEAR DOWN With BASCOM, again it is very easy task. To generate PWM, the statement is Config Timer1 = Pwm, Pwm = 8, Prescale = 1, Compare A Pwm = Clear Down, Compare B Pwm = Clear Down Start Timer1 Timer1 is a 16 bit timer which actually works in two parts, each one of 8 bit, simultaneously. So the above statement is actually generating two PWMs, PWM 1A and PWM 1B. Same way timer 2 can be configured. Refer ATmega16/32 datasheet and BASCOM help for more information regarding timers and PWM generation.

Sample Program defining the header and conf... Files:


Header files: $regfile = "8535def.dat" // instruct the compiler to use the amtega16 register file. $crystal = 4000000 //set the internal crystal to 4 MHz. Configuration files: Config Lcd = 16 * 2 //config the LCD display Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2 // config the LCD pin Copyright 2010: Yantrik Automation 10

Yantrik Automation
www.yantrik.in Config Adc = Single, Prescaler = Auto, Reference = Avcc // config A/D converter Start ADC Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down //configure timer1 , to generate pwm Start Timer1 4.4 Defining Variables To define a variable in BASCOM, the syntax is: Syntax DIM var AS type Var- Name of Variable Type - Bit, Byte, Word, Integer, Long, Single, Double or String Example Dim A as Integer Dim B as String * 8 First statement is defining A variable as integer and second one is defining B variable as String of 8 characters long. Other than Integer and String there many data types available in BASCOM. To know more about all data types, refer the help provided in BASCOM.

4.5 Start Command This command is use to start the specified device. Syntax START device Device - TIMER0, TIMER1, COUNTER0 or COUNTER1, WATCHDOG, AC (Analog comparator power) or ADC(A/D converter power) Example Start ADC 4.6 CLS Command
Clear the LCD display and set the cursor to home.

Copyright 2010: Yantrik Automation 11

Yantrik Automation
www.yantrik.in
Syntax/ Example Cls

4.7 If Else statement, Loops and Select case statement BASCOM allows using all types of loops in the program like do, while and for. Concept of using these loops is same as using them in other languages like C. Given below are syntaxes of all loops you can use in BASCOM 1. Do Loop Do <statements> Loop

2. Do until Loop Do <statements> Loop until (condition) 3. While Loop While (condition) <statements> Wend 4. If else statement If (condition) then <Statements> else <statements> endif 5. If elseif else ladder statement If (condition) then <statements> else if (condition) <statements> else <statements> endif 6.For loop Copyright 2010: Yantrik Automation 12

Yantrik Automation
www.yantrik.in For (varname) = (starting point) To (end point) STEP (value) <statements> Next Example of For loop For A = 1 To 5 STEP 1 Print Hello Next 7. Case Select Statement select case varname case (test1 varname) <statement> case (test2 varname) <statement> case else <statement> End select

4.8 GETADC command This command is used to take input from the analog sensor connected to the development board. This command retrieves the analog value from channel 0-7 of port A. The range of analog value is from 0 to 1023. Syntax var = GETADC(channel [,offset]) Var - The variable in which the value will be stored. Channel It is the pin no of port A to which anolog sensor is connected. Offset It is an optional numeric variable that specifies gain or mode. Example p = Getadc(1) Here, in above example, the analog value of the input provided by the sensor connected to pin 2 of port A is stored in variable L.

Copyright 2010: Yantrik Automation 13

Yantrik Automation
www.yantrik.in 4.9 LCD Command It is used to display a constant or variable on LCD screen. Syntax LCD x X - Variable or constant to be displayed on LCD For displaying string / text, Use LCD text For displaying variable, Use LCD A (A refers to the variable) For displaying text/variable in next line, we use command LOWERLINE Example Lcd a; Yantrik Lowerline Lcd Automation Output on LCD will be: Value of Variable a , Yantrik Automation

4.10 Waitms command Suspends program execution for a given time in mS. Syntax WAITMS T T-The number of milliseconds to wait. (1-65535) Example Waitms 200 4.11 PWMXX command It is used to set the speed of motor Syntax PwmXX = value Copyright 2010: Yantrik Automation 14

Yantrik Automation
www.yantrik.in Xx- it is the channel of a motor Value any integer value ranging from 0 to255 (maximum speed). Example Pwm1a = 130

// refer to Page 6 for details about motor connector

4.12 PORTX.y command PORTX.y it is used to set the direction of the motor Syntax PORTX.y = value X.y - X as port number and y as pin number Value - 0 for clock rotation and 1 for anti clock rotation Example: Portd.6 = 1 // refer to page 6 for details about motor connector

4.13 Controlling Output Ports The output ports in YA Development board are defined as Motor 1 and Motor 2. They are use to drive the motors as well they can be used to trigger any other event. The speed and direction of motor can be controlled using commands defined in 4.11 and 4.12 i.e defining PWM for speed and configuring PortX.y for direction. Example: Pwm1b = 150 - set the speed of motor 1 Portd.6 = 0 - set the direction of motor 1 Pwm1a = 150 - set the speed of motor 2 Portd.7 = 0 - set the direction of motor 2 Important Note: Here motor 1 and motor 2 refers to DC motors connected to terminal blocks. Wires of left motor will be inserted into first 2 connector of terminal 2. Wires of right motor will be inserted into last 2 connector of terminal 2. Similarly, we can connect 2 DC motors to terminal 1of development board. To move the motor into Backward direction, set PWM1a=0 and PWM1b =0.

Copyright 2010: Yantrik Automation 15

Yantrik Automation
www.yantrik.in PROGRAMMING STEPS: Step1Open bascom avr from start menu, click files >> new and write header files and the configuration files in it.

Step2Now make use of the desired loop and start with the programming. Step3Once the programming is done, press F7 to compile. Step4Plug in the USB programming cable in you computer. Now install the driver of the usb programmer which you will find in the folder named WINDRIVER. Just give the location of this folder when the computer asks for the driver. Step5Now open avrdude-gui which will help you to transfer the hex code of your programme to the microcontroller. Configure and Load the files in the GUI as per the instructions shown in image below. AVRDude- GUI looks like: After configuring, clicks execute to load the HEX file into microcontroller. Once the file is loaded, please check the status in the window below. Copyright 2010: Yantrik Automation 16

Yantrik Automation
www.yantrik.in

SAMPLE CODES
1-LCD interface and display $regfile = "8535def.dat" ' $crystal = 4000000 Config Lcd = 16 * 2 Config Lcdpin = Pin, Db4 = Portb.4, Db5 = Portb.5, Db6 = Portb.6, Db7 = Portb.7, E = Portb.3, Rs = Portb.2 Config Adc = Single, Prescaler = Auto, Reference = Avcc Config Timer1 = Pwm, Pwm = 8, Prescale = 1, Compare A Pwm = Clear Down, Compare B Pwm = Clear Down Copyright 2010: Yantrik Automation 17

Yantrik Automation
www.yantrik.in Start Adc Cls Start Timer1 Do cls Lcd "Yantrik Lowerline Lcd Automation Waitms 200 End 2-Metro Train Prototype $regfile = "8535def.dat" $crystal = 1000000 Config Lcd = 16 * 2 Config Lcdpin = Pin, Db4 = Portb.4, Db5 = Portb.5, Db6 = Portb.6, Db7 = Portb.7, E = Portb.3, Rs = Portb.2 Config Timer1 = Pwm , Prescale = 1 , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Start Timer1 Do Cls Lcd "forward" Pwm1a = 200 Portd.7 = 0 Pwm1b = 200 Portd.6 = 0 Waitms 2000 Cls Lcd "left" Pwm1a = 200 Portd.7 = 0 Pwm1b = 50 Portd.6 = 0 Waitms 1000 Cls Lcd "right" Pwm1a = 50 Copyright 2010: Yantrik Automation 18

Yantrik Automation
www.yantrik.in Portd.7 = 0 Pwm1b = 200 Portd.6 = 0 Waitms 1000 Cls Lcd "stop" Pwm1a = 0 Portd.7 = 0 Pwm1b = 0 Portd.6 = 0 Waitms 1000 Cls Lcd "backward" Pwm1a = 50 Portd.7 = 1 Pwm1b = 50 Portd.6 = 1 Waitms 2000 Cls Loop End 3-Sensor Calibration $regfile = "8535def.dat" $crystal = 4000000 Config Lcd = 16 * 2 Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2 Config Adc = Single , Prescaler = Auto , Reference = Avcc Start ADC Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Start Timer1 Dim S As integer // declaring variable S of type integer Cls // Clear screen Do // Start the loop Copyright 2010: Yantrik Automation 19

Yantrik Automation
www.yantrik.in cls S= GetADC (0) // The input of sensor connected to Pin 0 of port A will be stored in variable S. Here, in this case, Pin 0 refers to ADC1connector of Development Board Lcd S // Display the value of variable S on LCD Waitms 200 Loop // End of Loop End // to end the program 4-Real Time Temperature Monitoring $regfile = "8535def.dat" $crystal = 4000000 Config Lcd = 16 * 2 Config Lcdpin = Pin, Db4 = Portb.4, Db5 = Portb.5, Db6 = Portb.6, Db7 = Portb.7, E = Portb.3, Rs = Portb.2 Config Adc = Single, Prescaler = Auto, Reference = Avcc Start ADC Config Timer1 = Pwm, Pwm = 8, Prescale = 1, Compare A Pwm = Clear Down, Compare B Pwm = Clear Down Start Timer1 Dim S As integer // declaring variable S of type integer Cls // Clear screen Do cls // Start the loop S= GetADC (0) // the input of sensor connected to Pin 0 of port A will be Stored in variable S. Here, in this case, Pin 0 refers to ADC1 connector of Development Board Lcd Current // Display the value of variable S on LCD Lowerline Lcd room temp-S Waitms 200 Loop // End of Loop End // to end the program 5-Obstacle Avoidance $regfile = "8535def.dat" $crystal = 1000000 Copyright 2010: Yantrik Automation 20

Yantrik Automation
www.yantrik.in Config Lcd = 16 * 2 Config Lcdpin = Pin, Db4 = Portb.4, Db5 = Portb.5, Db6 = Portb.6, Db7 = Portb.7, E = Portb.3, Rs = Portb.2 Config Adc = Single, Prescaler = Auto, Reference = Avcc Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Start Adc Cls Start Timer1 Dim R As Integer Do Cls R = Getadc(0) If R > 600 Then Pwm1b = 0 Portd.6 = 0 Pwm1a = 0 Portd.7 = 0 Lcd "obstacle found" Lowerline Lcd "stop" Elseif R < 600 Then Pwm1b = 255 Portd.6 = 0 Pwm1a = 255 Portd.7 = 0 Lcd "no obstacle found" Lowerline Lcd "move" End If Loop End 6-Object Follower $regfile = "8535def.dat" $crystal = 1000000 Config Lcd = 16 * 2 Config Lcdpin = Pin, Db4 = Portb.4, Db5 = Portb.5, Db6 = Portb.6, Db7 = Portb.7, E = Portb.3, Rs = Portb.2 Copyright 2010: Yantrik Automation 21

Yantrik Automation
www.yantrik.in Config Adc = Single, Prescaler = Auto, Reference = Avcc Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Start Adc Cls Start Timer1 Dim R As Integer Do Cls R = Getadc(0) If R > 600 Then Pwm1b = 0 Portd.6 = 0 Pwm1a = 0 Portd.7 = 0 Lcd "no object" Lowerline Lcd "stop" Elseif R < 600 Then Pwm1b = 255 Portd.6 = 0 Pwm1a = 255 Portd.7 = 0 Lcd "follow object" Lowerline Lcd "move" End If Loop End 7-Line follower $regfile = "8535def.dat" $crystal = 4000000 Config Lcd = 16 * 2 Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2 Config Adc = Single, Prescaler = Auto, Reference = Avcc Copyright 2010: Yantrik Automation 22

Yantrik Automation
www.yantrik.in Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Start Adc Cls Start Timer1 Dim L as Integer, C as Integer, R as Integer Dim Lw as Integer, Lb as Integer, Lm as Integer Dim Cw as Integer, Cb as Integer, Cm as Integer Dim Rw as Integer, Rb as Integer, Rm as Integer Lcd "caliberate on" Lowerline Lcd "white surface" Waitms 2000 Cls Lcd "configuring" Lw = Getadc(0) Cw = Getadc(1) Rw = Getadc(2) Waitms 500 Cls Lcd "caliberate on" Lowerline Lcd black surface" Waitms 2000 Cls Lcd "configuring" Lb = Getadc(0) Cb = Getadc(1) Rb = Getadc(2) Waitms 500 Cls Lcd "mean" Lm = Lw + Lb Lm = Lm / 2 Rm = Rw + Rb Rm = Rm / 2 Cm = Cw + Cb Copyright 2010: Yantrik Automation 23

Yantrik Automation
www.yantrik.in Cm = Cm / 2 Waitms 500 Cls Do Cls L = Getadc(0) C = Getadc(1) R = Getadc(2) Lcd L; "--; C; "--; R If L < Lm and C > Cm and R < Rm Then Pwm1b = 150 Portd.6 = 0 Pwm1a = 150 Portd.7 = 0 Lowerline Lcd "forward" Elseif L < Lm and C > Cm and R > Rm Then Pwm1a = 0 Portd.7 = 0 Pwm1b = 100 Portd.6 = 0 Lowerline Lcd "right" Elseif L < Lm and C < Cm and R > Rm Then Pwm1a = 30 Portd.7 = 0 Pwm1b = 120 Portd.6 = 0 Lowerline Lcd "right" Elseif L > Lm and C < Cm and R < Rm Then Pwm1a = 120 Portd.7 = 0 Pwm1b = 30 Portd.6 = 0 Lowerline Copyright 2010: Yantrik Automation 24

Yantrik Automation
www.yantrik.in Lcd "left" Elseif L > Lm and C > Cm and R < Rm Then Pwm1a = 100 Portd.7 = 0 Pwm1b = 0 Portd.6 = 0 Lowerline Lcd "left" End If Loop End 8-PC Controlled Code A (Wired) $regfile = "8535def.dat" $crystal = 4000000 $baud = 9600 $prog&Hff , &HC4 , &HD9 , &H00 Config Lcd = 16 * 2 Config Lcdpin = Pin, Db4 = Portb.4, Db5 = Portb.5, Db6 = Portb.6, Db7 = Portb.7, E = Portb.3, Rs = Portb.2 Config Adc = Single, Prescaler = Auto, Reference = Avcc Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Dim A as String * 10 Start Adc Cls Start Timer1 Do A = Waitkey() If A = "f" Then Print "moving forward" Cls Lcd "forward" Pwm1a = 255 Portd.7 = 0 Copyright 2010: Yantrik Automation 25

Yantrik Automation
www.yantrik.in Pwm1b = 255 Portd.6 = 0 Cls Elseif A = "l" Then Print "moving left" Cls Lcd "left" Pwm1a = 255 Portd.7 = 0 Pwm1b = 0 Portd.6 = 0 Cls Elseif A = "r" Then Print "moving right" Cls Lcd "right" Pwm1a = 0 Portd.7 = 0 Pwm1b = 255 Portd.6 = 0 Cls Elseif A = "s" Then Print "stop" Cls Lcd "stop" Pwm1a = 0 Portd.7 = 0 Pwm1b = 0 Portd.6 = 0 Cls Elseif A = "b" Then Print "moving backward" Cls Lcd "backward" Pwm1a = 0 Portd.7 = 1 Pwm1b = 0 Copyright 2010: Yantrik Automation 26

Yantrik Automation
www.yantrik.in Portd.6 = 1 Cls End If Loop End

5. Precautions
Here are a few things you need to take care to prevent your board being damaged As in DC voltage polarity is of prime importance so the power terminals should be connected properly. This board works perfect with current range of 0.5 1.5 amps on full load conditions. So it is advised to use the same. Do not short any pin or any soldering point on the board. Whenever you connecting any external device the exact pin connections are to be kept in mind. Do not use motors which need more than 1.2 amps current as L293D is capable of upto 1.2 Amps only. Always switch off while connecting or disconnecting ISP cable. After programming, always prefer to disconnect the usb cable before executing the program.

6. Troubleshooting

For any problem in the code please refer the help section of bascom. For any hardware problem please refer the component datasheet.

For any special query related to hardware or software please mail us at:info@yantrik.in Copyright 2010: Yantrik Automation 27

Yantrik Automation
www.yantrik.in

7. NOTES

Copyright 2010: Yantrik Automation 28

You might also like