bascom avr tft lcd factory
Included in this sample is a tutorial how you cam make your own characters with my converter tool. This tool converts the Maxim mcm files to Bascom data lines.
HMI module (Human-Machine Interface) with a color LCD TFT 2.4" display with a resolution of 320x240 px. It is equipped with a resistive touch panel that ensures user interaction with the system being built. The panel has a built-in microcontroller that controls the display, a microSD card slot and Flash memory The module communicates with an external driver via the UART interface, thanks to which it can work with popular development kits, such as Arduino, Raspberry Pi or STM32. It is powered with a voltage of 5 V using the attached module and cables. all projects where a user control panel is required, e.g. on production lines.
Special commands for LCD-displays , I2C chips and 1WIRE chips, PC keyboard, matrix keyboard, RC5 reception, software UART, SPI master and slave, IR remote code, graphical LCD"s
Ich bin jetzt mit der Entwicklung fertig und wir möchten nun in die Serie gehen. Zum Entwickeln ist der KITEditor / ELECTRONIC ASSEMBLY LCD Tools zwar sehr praktisch, aber in der Fertigung möchte ich mit einer Batchdatei (*.bat) oder einem Stand-Alone-Programmer arbeiten um die Makros ins Display zu laden. Haben Sie dazu ein Tool ?
Der eDIP-Kompiler (KitEditor) erstellt eine Makrodatei *.df. Diese liegt im Projektverzeichnis (wenn nicht anders angegeben). Diese Datei enthält alle Informationen einschliesslich der Programmierbefehle, sodass Sie diese mit jedem x-beliebigen System zum EA eDIPTFT übertragen können.
Dazu übertragen Sie den Inhalt der *.df Datei 1:1 (natürlich mit Smallprotokoll in 128 Byte Pakete verpackt) zum eTFT. Unabhängig von der verwendeten Schnittstelle. Zusätzliche Komandos sind nicht notwendig.
Ich möchte mit dem TFT-Display eine Schaltuhr programmieren und diese im Programm integrieren, um verschiedene Vorgänge zu unterschiedlichen Zeiten ausführen zu können.
Ich setze in einem Gerät das Display EA eDIPTFT43 ein. Derzeit muss ich es vor dem Einbau mit dem Programmer programmieren. Will ich nachträglich etwas verändern, muss ich es ausbauen und neu programmieren.Das ist recht umständlich. Alle anderen Microcontrollersysteme in dem Gerät kann ich derzeit im eingebauten Zustand über entsprechende Bootloader programmieren, nur das Display nicht.
Wenn ich mit meinem eDIP TFT 4,3" mit der Bargraphanzeigen arbeite, ergibt sich folgendes Problem:Beim Steuern des Bargraphs per Touchpanal reagiert der Bargraph nach häufigen Betätigen (ca. 30 mal) nicht mehr.
Drive:\ELECTRONIC_ASSEMBLY_LCD-Tools-Portable\Data\eDIP ‒ intelligent graphics displays\your eDIP\How to use...Just select a term you are interested in and open the *.kmi file with the help of KitEditor.
I have problem with your intelligent LCD EA eDIP240-7. When I try to write using the virtual keyboard, several letters do not print: “R ” – “L ” – “C ”. This always happens in the simulator and also in real embedded applications when I try to write these 3 capital letters. With other letters everything looks OK.
Ich bin jetzt mit der Entwicklung fertig und wir möchten nun in die Serie gehen. Zum Entwickeln ist der KITEditor / ELECTRONIC ASSEMBLY LCD Tools zwar sehr praktisch, aber in der Fertigung möchte ich mit einer Batchdatei (*.bat) oder einem Stand-Alone-Programmer arbeiten um die Makros ins Display zu laden. Haben Sie dazu ein Tool ?
The EA KIT editor (ELECRONIC ASSEMBLY LCD Tools) is the right tool for that. When the USB driver is correctly installed , connect the display to the USB.
Bei den LCD-Modulen mit dem Kontroller KS0073 gibt es das zusätzliche RE-Bit, dass über das FunctionSetRegister gesetzt und zurückgesetzt werden kann. Nur wenn das RE-bit gesetzt ist, können Sie das Display auf "4- zeilig" initialisieren.
Bei den LCD-Modulen mit dem Kontroller KS0073 gibt es das zusätzliche RE-Bit, dass über das FunctionSetRegister gesetzt und zurückgesetzt werden kann. Nur wenn das RE-bit gesetzt ist, können Sie das Display auf "4- zeilig" initialisieren.
Frage:Nachdem ich in den vergangenen Wochen mehrere Tage damit vergeudet habe, ein EA DIP204-4 Display an einem ATiny2313 sowie an einem Atmega48 programmiert mit Bascom zum Laufen zu bringen möchte ich hiermit meinen Frust loswerden.......
Aber mit Bascom kriege ich das Display einfach nicht zum laufen.Antwort:Leider ist die BASCOM-Hilfe falsch. Es genügt, das Display mit::::::::::::::::::::::::::::::::::::::::::::Config Lcd = 20 * 4a , Chipset = Ks077::::::::::::::::::::::::::::::::::::::::::::(kein Schreibfehler) anstelle von
Das LCD DIP204-4 funktioniert im SPI-Modus nicht. Im 4-bit-Parallel Modus funktioniert das LCD. Die Brücke wurde entsprechend auf SPI gesetzt, bzw. die Lötstelle wurde auch später aufgelöst und auf Custom PINs/Jumper geleitet um das ständige Löten zu vermeiden.
I just purchased the EA DOGXL160-7 display and a touch panel. I am looking for data sheets on the above-mentioned product. The only thing I could find on your website is the application example for the touch panel which shows how to connect the touch panel to an ATmega AVR processor and nothing else. This application example does not provide any information on how the touch panel works.
I just purchased the EA DOGXL160-7 display and a touch panel. I am looking for data sheets on the above-mentioned product. The only thing I could find on your website is the application example for the touch panel which shows how to connect the touch panel to an ATmega AVR processor and nothing else. This application example does not provide any information on how the touch panel works.
Ich habe soeben den Fehler bei der Ansteuerung des von mir verwendeten DOG-M-Displays gefunden: Der LCD-Chipsatz ist sehr kritisch bei dem Timing des tCSH (vgl. ST7036 Datasheet S 55). Vorgeschrieben sind 200-350ns.
Our factory is looking for a graphics LCD for our prototype. I read somewhere that you sell displays ‒ and I even found the type ‒ 320x240STN with CFL backlight (EA 7320-7.9NC), but I would like to have some technical information about it: I would like to know:
3. For driving the LCD you need a controller chip like SED 1330 or MSM 6255 and some drivers, display memory and a decoder. Then you have to write software with graphics routines, fonts ...
Unser Grafik-LCD mit 128x128 Punkten hat ein Sichtfenster von 62 x 62 mmm. Die Außenabmessungen betragen 85 x 100 mm und es ist sowohl mit EL- Beleuchtung als auch mit einer langlebigen LED-Beleuchtung lieferbar. Durch den integrierten Kontroller T6963 ist es somit softwarekompatibel.
So. Nun sollte zumindest die 1. Zeile grau oder schwarz erscheinen. In der Initialisierung ist der Function Set das Wichtigste; hier muß Number of display lines bei 1-zeiligen Displays mit N=0 programmiert werden und bei 2- und 4-zeiligen LCD´s ist N=1. Nach Erhalt dieses Befehls müssen alle Zeilen gleichmäßig und sehr blaß sichtbar sein. Alle weiteren Initialisierungen nehmen Sie nach Belieben vor.
Wenn Sie dann immer noch nichts sehen, überprüfen Sie mal die Spannungsversorgung direkt am Display: Zwischen Pin 1 und Pin 2 müssen Sie 3,6-6V messen, zwischen V0 und VLCD sollen es ca. 6,5V sein (Abhängig vom Kontrast). Sie benötigen also in jedem Fall eine negative Versorgungsspannung von -0,5 bis zu -3,5V.
Bei den LCD-Modulen mit dem Kontroller KS0073 gibt es das zusдtzliche RE-Bit, das ьber das FunctionSetRegister gesetzt und rьckgesetzt werden kann. Nur wenn das RE-bit gesetzt ist, kцnnen Sie das Display auf "4- zeilig" initialisieren.
I would like to have more information about your EA KIT240-7. I am also looking for a display unit (probably LCD) that can display 2 or 3 lines and about 15 to 20 characters in each line. This unit should be about 3 to 4cmx10 to 15cm , it should work in dark conditions and I want to control it via an RS-232.
Wir sind Anbieter einer DNC Datenübertragungslösung und sind auf der suche nach einem kleinen LCD Monitor, welcher uns die Bildschirmanzeige des ca. 100 Meter entfernten DNC Systems anzeigt. Ist das möglich ?
Alternativ dazu empfehlen wir Ihnen das Displays EA KIT240-6LED (Datenblatt 1074kB) und die Diskette EA DISKFONT6963. Auf der Diskette sind 2 kyrillische Zeichensätze enthalten, welche sie per RS-232 in das LCD laden können. Der mitgelieferte Fonteditor erlaut auch die Erstellung komplett eigener Fonts; auch schon bei 1 Stück.
Inquiry: I need a voltmeter in modular design to measure 150-250 V AC. Execution in LED or LCD is irrelevant. If you offer something like that, I would be interested in product information.
Hkipnik ist wohl grad nicht online, er hatte dies mal - ich denke im alten Forum - gepostet, es gibt wohl kein Display, das er nicht schon - dankenswerterweise - für Bascom angepasst hat.
Den CS. Aber in dem Fall nicht. Das Noss = 1 heißt das die Spi Hardware sich nicht darum kümmern soll. (Geht ja auch nicht wenn verschiedene Slaves angeschlossen sind (Lcd und SD, evt auch noch derTouch-Controller). Die Software nutzt dazu den Pin B.7 . Den gibts auch beim 328. Wenn möglich übernehmen, dann braucht er nicht überall im Programm geänert werden.
What is a computer? ................................................................................................................... 95 What does a computer system do? ............................................................................................. 95 What exactly is a microcontroller? ............................................................................................... 96 What does a microcontroller system do?..................................................................................... 97 What you do when learning to program ....................................................................................... 98 AVR microcontroller hardware .................................................................................................... 99 Power supplies............................................................................................................................ 99 BASCOM and AVR assignment ................................................................................................ 100 Programming words you need to be able to use correctly ......................................................... 102
11 Getting started with AVR Programming ........................................................................ 103 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8
Breadboard ............................................................................................................................... 103 Breadboard+Prototyping board circuit ....................................................................................... 104 Alternative ATTiny461 breadboard circuit.................................................................................. 106 Alternative ATMega48 breadboard circuit ................................................................................. 107 Alternative ATMega breadboard circuit ..................................................................................... 108 AVR circuit description .............................................................................................................. 109 Output Circuit - LED .................................................................................................................. 110 AVR programming cable ........................................................................................................... 110
12 Getting started with Bascom & AVR .............................................................................. 111 12.1 12.2 12.3 12.4 12.5 12.6 12.7
The compiler ............................................................................................................................. 111 The programmer ....................................................................................................................... 111 An introduction to flowcharts ..................................................................................................... 112 Bascom output commands ........................................................................................................ 113 Introducing ‘bugs’ to see what happens .................................................................................... 114 Getting started code for the ATMega48 .................................................................................... 115 Getting started code for the ATMega8535................................................................................. 116
Variables - numbers inside the AVR.......................................................................................... 134 Pedestrian crossing lights controller .......................................................................................... 135 Pedestrian Crossing Lights schematic ...................................................................................... 136 Pedestrian Crossing Lights PCB Layout.................................................................................... 137 Algorithm planning example – pedestrian crossing lights .......................................................... 138 Flowchart planning example – pedestrian crossing lights .......................................................... 139 Program example - pedestrian crossing lights ........................................................................... 140 Modification exercise for the pedestrian crossing ...................................................................... 141 Changing a variable – simple stepping/counting ....................................................................... 142 For-next tricks with flashing LEDs ......................................................................................... 144 For-Next ................................................................................................................................ 145 Using variables for data......................................................................................................... 147 Types of memory .................................................................................................................. 147 Binary and Hexadecimal numbers ......................................................................................... 148 Learning to count in binary .................................................................................................... 149 Learning some Hexadecimal (HEX) ...................................................................................... 150 Rules about variables ............................................................................................................ 153 a few examples of variables in use ........................................................................................ 153 Random Numbers ................................................................................................................. 154 The Bascom-AVR simulator .................................................................................................. 155 Variables research assignment ............................................................................................. 157 Byte variable limitations......................................................................................................... 158 Electronic dice project ........................................................................................................... 159 Programming using variables – dice...................................................................................... 159 Dice layout stage 1................................................................................................................ 160 Dice layout stage 2................................................................................................................ 161 Dice Layout final.................................................................................................................... 162 First Dice Program flowchart ................................................................................................. 163 A note about the Bascom Rnd command .............................................................................. 164 Modified dice ......................................................................................................................... 165 Multiple LEDs - 7 segment displays....................................................................................... 167 Programming using variables - sound ................................................................................... 173 Make a simple siren .............................................................................................................. 175 Quiz Game Controller............................................................................................................ 177 Quiz game controller system context diagram ....................................................................... 177 Quiz game controller block diagram ...................................................................................... 178 Quiz game controller Algorithm ............................................................................................. 179 Quiz game schematic ............................................................................................................ 180 Quiz game board veroboard layout ....................................................................................... 181 Quiz Controller flowchart ....................................................................................................... 186 "Quiz Controller program code ............................................................................................... 187
31 LCDs (liquid crystal displays) ......................................................................................... 264 31.1 Alphanumeric LCDs .................................................................................................................. 265 ATTINY26 Development PCB with LCD ............................................................................................... 266 31.2 Completing the wiring for the LCD............................................................................................. 268 31.3 LCD Contrast Control ................................................................................................................ 269 31.4 Learning to use the LCD ........................................................................................................... 270 31.5 Adding more interfaces to the ATTiny26 Development board.................................................... 271 31.6 Ohms law in action – a multicoloured LED ................................................................................ 273 31.7 Repetition again - the ‘For-Next’ and the LCD ........................................................................... 275 31.8 Defining your own LCD characters ............................................................................................ 276 31.9 LCD custom character program ................................................................................................ 276 31.10 To CLS or not to CLS that is the question ............................................................................. 278 31.11 A simple digital clock ............................................................................................................. 279
Strings assignment ................................................................................................................... 296 ASCII Assignment ..................................................................................................................... 298 Time in a string ......................................................................................................................... 301 Scrolling message assignment .................................................................................................. 303 Some LCD programming exercises........................................................................................... 304
Microcontroller power limitations ............................................................................................... 305 Power ....................................................................................................................................... 307 Power dissipation in resistors .................................................................................................... 307 Diode characteristics ................................................................................................................. 308 Using Zener diodes ................................................................................................................... 309 How diodes work....................................................................................................................... 310 How does a LED give off light? ................................................................................................. 311 LCD Backlight Data ................................................................................................................... 312 Transistors as power switches .................................................................................................. 313 High power loads .................................................................................................................. 314 AVR Power matters............................................................................................................... 314 Darlington transistors - high power ........................................................................................ 316 ULN2803 Octal Darlington Driver .......................................................................................... 318 Connecting a FET backlight control to your microcontroller ................................................... 320 FET backlight control ............................................................................................................ 321
ADC - Analog to Digital conversion ........................................................................................... 344 Light level sensing .................................................................................................................... 344 Voltage dividers review ............................................................................................................. 345 AVR ADC connections .............................................................................................................. 345 Select-Case .............................................................................................................................. 346 Reading an LDR’s values .......................................................................................................... 348 Marcus’ Nightlight project .......................................................................................................... 350 Temperature measurement using the LM35 .............................................................................. 353 A simple temperature display .................................................................................................... 354 LM35 temperature display ..................................................................................................... 357 Voltage measurement using a voltage divider ....................................................................... 360 Variable power supply voltmeter program ............................................................................. 362 Force Sensitive Resistors ...................................................................................................... 364 Piezo sensor ......................................................................................................................... 364 Multiple switches and ADC .................................................................................................... 365
H-Bridge.................................................................................................................................... 373 H-Bridge Braking....................................................................................................................... 375 L293D H-Bridge IC .................................................................................................................... 376 L298 H-Bridge IC .................................................................................................................... 378 LMD18200 H-Bridge IC ............................................................................................................. 379 LMD18200 program .................................................................................................................. 382 Darlington H-Bridge .................................................................................................................. 383 Stepper motors ......................................................................................................................... 386 PWM - pulse width modulation .................................................................................................. 393 PWM outputs ........................................................................................................................ 394 Uses for PWM ....................................................................................................................... 395 ATMEL AVRs PWM pins ....................................................................................................... 396 PWM on any port .................................................................................................................. 397 PWM internals ....................................................................................................................... 398
40 AVR pull-up resistors ...................................................................................................... 400 41 Keypad interfacing........................................................................................................... 401 41.1 41.2 41.3 41.4 41.5 41.6
Analogue seconds display on an LCD ....................................................................................... 426 LCD big digits ........................................................................................................................... 429
Simplex and duplex ................................................................................................................... 499 Synchronous and asynchronous ............................................................................................... 499 Serial communications, Bascom and the AVR .......................................................................... 500 RS232 serial communications ................................................................................................... 501 Build your own RS232 buffer..................................................................................................... 503 Talking to an AVR from Windows XP ........................................................................................ 504 Talking to an AVR from Win7 .................................................................................................... 506 First Bascom RS-232 program .................................................................................................. 508 Receiving text from a PC .......................................................................................................... 509 BASCOM serial commands ................................................................................................... 510 Serial IO using Inkey() ........................................................................................................... 511 Creating your own software to communicate with the AVR ................................................... 514 Microsoft Visual Basic 2008 Express Edition ......................................................................... 515 Stage 1 – GUI creation .......................................................................................................... 516 Stage 2 – Coding and understanding event programming ..................................................... 525 Microsoft Visual C# commport application ............................................................................. 530 Microcontroller with serial IO. ................................................................................................ 535 PC software (C#) to communicate with the AVR ................................................................... 540 Using excel to capture serial data ......................................................................................... 544 PLX-DAQ .............................................................................................................................. 546 StampPlot ............................................................................................................................. 547 Serial to parallel .................................................................................................................... 549 Keyboard interfacing – synchronous serial data ........................................................................ 554 Keyboard as asynchronous data ............................................................................................... 561
56 Amplifier ........................................................................................................................... 608 57 Bike audio amplifier project ............................................................................................ 608 58 Graphics LCDs ................................................................................................................. 614 58.1 58.2 58.3
The T6963 controller ................................................................................................................. 614 Graphics LCD (128x64) – KS0108 ............................................................................................ 619 Generating a negative supply for a graphics LCD ..................................................................... 624
59 GLCD Temperature Tracking Project ............................................................................. 626 59.1 59.2 59.3 59.4 59.5 59.6 59.7
Low level languages:................................................................................................................. 638 AVR Internals – how the microcontroller works ......................................................................... 639 1. The 8bit data bus .................................................................................................................. 640 2. Memory ................................................................................................................................. 640 3. Special Function registers ..................................................................................................... 641 A simple program to demonstrate the AVR in operation ............................................................ 641
Keypad- polling versus interrupt driven ..................................................................................... 645 Improving the HT12 radio system by using interrupts ................................................................ 650 Magnetic Card Reader .............................................................................................................. 652 Card reader data structure ........................................................................................................ 652 Card reader data timing ............................................................................................................ 653 Card reader data formats .......................................................................................................... 654 Understanding interrupts in Bascom- trialling ............................................................................ 654 Planning the program ................................................................................................................ 657
69 SSD1928 based colour graphics LCD ............................................................................ 759 69.1 69.2 69.3 69.4 69.5 69.6 69.7 69.8 69.9 69.10 69.11 69.12 69.13 69.14 69.15 69.16 69.17 69.18 69.19 69.20 69.21 69.22
System block diagram ............................................................................................................... 759 TFT LCDs ................................................................................................................................. 760 System memory requirements .................................................................................................. 761 System speed ........................................................................................................................... 761 SSD and HX ICs ....................................................................................................................... 761 Colour capability ....................................................................................................................... 761 SSD1928 and HX8238 control requirements ............................................................................. 762 SSD1928 Software ................................................................................................................... 763 SSD1928 microcontroller hardware interface ............................................................................ 767 Accessing SSD control registers ........................................................................................... 768 SSD1928_Register_routines.bas .......................................................................................... 771 Accessing the HX8238. ......................................................................................................... 775 SSD1928_GPIO_routines.bas............................................................................................... 775 LCD timing signals ................................................................................................................ 777 HX setups ............................................................................................................................. 778 SSD setups ........................................................................................................................... 779 SSD line / HSync timing ........................................................................................................ 780 SSD row / VSync/ frame timing ............................................................................................. 781 HX and SSD setup routine .................................................................................................... 783 "SSD1928_HardwareSetup_Routines.bas ............................................................................. 783 SSD1928_Window_Control_Routines.bas ............................................................................ 787 Colour data in the SSD memory ............................................................................................ 790
Traffic Light help and solution ....................................................................................... 800 USB programmer - USBASP ........................................................................................... 806 USBTinyISP programmer ................................................................................................ 808 Various AVR development board schematics and layouts .......................................... 812 AVR Development Board 2 ....................................................................................................... 815 Dev board version 2 circuit diagram .......................................................................................... 816 Dev board pcb layout version 2 ................................................................................................. 817 ATMEGA V4b development board circuit – 12TCE 2011 .......................................................... 818 V4b devboard layout 12TCE 2011 ............................................................................................ 819 ATMega Dev PCB V5DSchematic (2012) ................................................................................. 820 ATMega Dev PCB V5DLayout (2012) ....................................................................................... 821 ATMega Dev PCB V5D Copper (2012) ..................................................................................... 822
128x64 GLCD Schematic – VerC -data on portB ...................................................................... 827 128x64 GLCD Layout – VerC –data on portB ........................................................................... 828 128x64 GLCD Schematic – VerD -data on portB ...................................................................... 829 128x64 GLCD Layout –VerD -data on portB ............................................................................. 830
1. Develop an understanding of what a computer is and build a correct mental model for one a. Input and output conversion at the voltage level b. Conversion of input and output voltages into data c. Processing and manipulating data which is stored in variables 2. Get to know about the hardware you are using a. Get a copy of the datasheet b. Learn about the power supply required c. Learn how to configure pins as either input or output d. Learn how to interface common I/O circuits: LED’s, Switches, Piezo, LDR… e. Find out about the different types of memory and amount of each f. Find out about the speed of processing 3. Get to know the language and the IDE you are using a. Learn to access the helpfile (e.g. highlight a word and press F1) b. The language has syntax (specific grammar/word rules) you must use correctly c. The IDE (Integrated Development Environment) has special commands and built in functions you must know and use: F7, F4, $crystal, $regfile, config, alias, const, port, pin d. Learn common I/O functions: set, reset, locate, LCD, GetADC e. Understand the limitations of and use variables: byte, word, long, single, double f. Use constants instead of numbers in the code (e.g. waitms timedelay) g. Get to know the control functions: Do-Loop (Until), For-Next, While-Wend, If-Then (Else) h. Get to know about text and math functions (read help file, write a few simple programs using the simulator) 4. Develop Algorithms (written plans for the process the program must carry out) a. Have a goal in mind for the program – use specifications and write a simple brief b. Plan your I/O by drawing a system block diagram c. Determine variables and constants required in the program d. Determine the state of all the I/O when the program begins e. Write the algorithm – Identify, order and describe the major processes the micro must do. 5. Draw Flowcharts or Statecharts (visual diagram for the process the program must carry out) a. Identify the blocks/states that will be used b. Use arrows to link the blocks and visualise control processes and program flow 6. Develop code from the flowcharts a. The outer looping line is replaced with a do-loop b. Backwards loops are replaced with do-loop do-loop-until, for-next, while-wend c. Forward loops are generally replaced with If-Then-EndIf d. Replace the blocks with actual commands e. Layout the code with correct indentations(tabs) to improve readability f. Learn to comment code so that it explains what is happening (not just describes) g. Use subroutines to organise complex code so that logic code is separate from I/O code h. Trial different ways of solving the problem and keep records of you experiments This is not a step by step process; as when you get to know about one area you get to know about others at the same time. The key to gaining depth in your knowledge and understanding comes from LOTS OF EXPERIMENTATION! That means making mistakes and above all having fun, you need to know that good decisions come from experience and experience comes from bad decisions!!! So experimenting is ok. In your electronics courses at school the aim is not to make you an expert in all the above (expertise comes after about 10 years working in an area), the aim is to introduce you to microcontroller electronics and programming, and to understand some of what is happening in the world around you and to feel able to see that you can control it and not have it control you. 98
A microcontroller is a general purpose electronic circuit; it is a full computer inside a single integrated circuit (IC or chip). Often ICs have fixed functions e.g. the TDA2822M amplifier or LM358 opamp, they only do one job and their input and output pins have fixed roles, so you have limited control over what they do, and therefore limited control over how to connect them. With a microcontroller however you are in control, you decide: what the function of the IC is what most of the pins are used for (inputs or outputs) and what external input/output devices these pins are connected to. If you want an egg timer, a car alarm, an infrared remote control or whatever, it can all be done with a microcontroller. A commercial range of microcontrollers called ‘AVR’ is available from ATMEL (www.atmel.com). You could start with the ATTiny461, it has 4kbytes of Flash for program storage, 128 bytes of Ram and 128 bytes of EEPROM for long term data storage. Or you could start with the ATMega48, it has 4kbytes of Flash, 512 bytes of RAM and 256 bytes of EEPROM. ATTiny461
The AVR is a microcontroller from which manufacturer________________ The URL for their website is: ________________________ Download the specific datasheet for our microcontroller (the summary version not the full version) and print the first 2 pages and put them in your journal. The Programmable Memory size is ______ The SRAM size is _______The EEPROM size is _______ The number of I/O lines is __________ and they are arranged in _______ports
BASCOM-AVR is a compiler from _____________________ The URL for their website is: ________________________ Download the latest version of the BASCOM AVR demo and install it on your PC. There are a number of application notes on the website for the AVR Describe what AN128 is about __________________________________________________________________________ __________________________________________________________________________ __________________________________________________________________________
There are a number of other great resource websites for the AVR and BASCOM Find 3 websites on the internet that have useful resource information on BASCOM List the websites URL and what you found there __________________________________________________________________________ __________________________________________________________________________ __________________________________________________________________________ __________________________________________________________________________ __________________________________________________________________________ __________________________________________________________________________ __________________________________________________________________________
11 Getting started with AVR Programming Microcontrollers, such as the ATMEL AVR, are controlled by software and they can do nothing until they have a program inside them. The AVR programs are written on a PC using BASCOM-AVR. This software is a type of computer program called a compiler, it comes from www.mcselec.com. It comes in a freeware version so students may download it and use it at home. The AVR is connected to the PC with a 5 wire cable.
The 5 pin header (connector) is for programming the AVR from a PC. The 0.1uF capacitor between 0V and VCC is to reduce any variations in power supply voltage. The 10k is a pull-up resistor for the reset pin, a low (connection to ground) on this pin will halt the microcontroller and when it is released(pulled high by the resistor) the program will run from the beginning again. The 1N4148 is a protection diode that will stop high voltages possibly damaging the microcontroller (it is only required on the reset pin because all the other microcontroller pins have built in protection diodes). The 0.1uF capacitor and 100R resistor are the power supply for the ADC circuit
A five wire cable is needed to connect the AVR circuit to a PC. It connects the PC’s parallel port to the AVR circuit. One end has a DB25M connector on it (as in this picture)
12 Getting started with Bascom & AVR BASCOM-AVR is four programs in one package, it is known as an IDE (integrated development environment); it includes the Program Editor, the Compiler, the Programmer and the Simulator all together.
When you have successfully compiled a program pressing F4 or the green IC picture in the toolbar starts the programmer. If no microcontroller is connected an error will pop up. If the IC s connected then the BASCOM completes the programming process and automatically resets your microcontroller to start execution of your program.
Flash1LEDv1.bas Type the code below into BASCOM, save it, then F7 to compile and then F4 to program ‘ Flash1LEDv1.bas "-----------------------------------------------" Compiler Setup (this tell Bascom things about our micro) $regfile = "attiny461.dat" "bascom must know the micro $crystal = 1000000 "bascom must know its speed "-----------------------------------------------" Hardware Setups " (these tell bascom how to setup our micro) Config Porta = Output "LEDs on port "-----------------------------------------------" Declare Constants " (these tell bascom names we will use for numbers " in our program, this makes it easy "to change things quickly later) Const Flashdelay = 150 ‘ preset how long a wait will be "-----------------------------------------------Do ‘start of a loop Porta = &B10000000 ‘ LED 7 on Waitms Flashdelay ‘wait a preset time Porta = &B00000000 ‘all LEDs off Waitms Flashdelay ‘wait a preset time Loop ‘return to do and start again End YOU NEED TO INDENT CODE BETWEEN ALL CONTROL STRUCTURES SUCH AS WITH THIS DO-LOOP, it really helps make your code more readable and easier to debug! Use the TAB key in Bascom to do it.
This is a typical first program to test your hardware Every line of the code is important. $regfile=”attiny461.dat”, Bascom needs to know which micro is being used as each micro has different features; this is the name of a file in the Bascom program folder with every detail about the ATTiny461. $crystal=1000000, This line tells Bascom the speed at which our microcontroller is executing operations 1 million per second)so that Bascom can calculate delays such as waitms properly Config porta=output, each I/O must be configured to be either an input or output; (it cannot be both at once) Const Flashdelay=150, ‘constants’ are used in a program, it is easier to remember names and it is useful to keep them all together in one place in the program (this is a code of practice). DO - LOOP statements enclose code which is to repeat forever; when programming it is important to indent (tab) code within loops; this makes your code easier to follow (this is a code of practice). Waitms flashdelay wait a bit, a microcontroller carries out operations sequentially, so if there is no pause between turning an LED on and turning it off the led will not be seen flashing Output Code Porta = &B10000000 make porta.7 high (which will turn on the LED connected to that port) and make all the other 7 output pins on that port low Porta = 0 make all 8 pins on porta low (which will turn off any LEDs connected to that port)
In the code throughout this book different AVR microcontrollers are referred to in different places. So take special note of the $regfile and $crystal commands used and make sure they match the micro you are using. Note that the ATTiny461 and ATMega48 both run by default at 1,000,000MHz while the ATMega8535 runs at 8,000,000 MHz. You will also have to make changes to the ports used in the program: the ATTiny461 has ports A & B, the ATMega48 has B, C & D, the Amega8535 ahd ports A, B, C & D.
Note the change to $regfile and $crystal (If the timing of the flashing is wrong then try $crystal=1000000 (as AVRs often come setup at 1MHz not 8 MHz)
"this program shows how to write code which controls the whole port at "once using the commands portA=&B0000000, rather than individual set and ‘reset commands which are very wasteful of code space when multiple LEDs ‘have to "be contolled (excellence comment) "-----------------------------------------------------------------" Compiler Setup (these tell Bascom things about our micro) $regfile = "attiny461.dat" "bascom needs to know the micro $crystal = 1000000 "bascom needs to know its speed "-----------------------------------------------------------------" Hardware Setups (these tell bascom how to setup our micro) " setup direction of all ports Config Porta = Output "LEDs on portA Config Portb = Input "switches on portB " Hardware Aliases (these tell bascom names we will use for I/O devices " attached to the Micro, names are easier to remember that ports) Config Porta = Output Config Portb = Output "-----------------------------------------------------------------" Declare Constants (these tell bascom names we will use for numbers in " " our program, this makes it easy to change things quickly later) " times have been made shorter for testing purposes Const Delaytime = 25 Do Porta = &B10000000 "1 =A.7 Waitms Delaytime Porta = &B01000000 "2 =A.6 119
Bascom’s sound command can be used to directly make a tone. Piezo alias portA.3 Sound piezo, 500, 300 ‘that’s all that’s required The Bascom sound command has three parameters (values) attached ot it. The port or pin of the microcontroller used The duration of the sound (number of pulses) The time the pin is high and low for. This command is not easy to use to get accurate tones from your AVR, but they do make useful sounds. Experiment with the sound command and make a series of tones suitable for an alarm. "-----------------------------------------------------------------" Compiler Setup (these tell Bascom things about our micro) $regfile = "attiny461.dat" "bascom needs to know the micro $crystal = 1000000 "bascom needs to know its speed "-----------------------------------------------------------------" Hardware Setups (these tell bascom how to setup our micro) " setup direction of all ports Config Porta = Output "LEDs on portA Config Portb = Output "switches on portB " Hardware Aliases (these tell bascom names we will use for I/O devices " attached to the Micro, names are easier to remember that ports) Leda4 Alias Porta.4 Piezo Alias Portb.3
"-----------------------------------------------------------------" Declare Constants (these tell bascom names we will use for numbers in " " our program, this makes it easy to change things quickly later) " times have been made shorter for testing purposes Const Flashdelay = 150
In this first program we would like the LED to change from off to on every time the switch is pressed. “When the switch is pressed change the LED” "-----------------------------------------" Compiler Setup (these tell Bascom things about our micro) $regfile = "attiny461.dat" "bascom needs to know the micro $crystal = 1000000 "bascom needs to know its speed "----------------------------------------" Hardware Setups (these tell bascom how to setup our micro) " setup direction of all ports Config Porta = Output "LEDs on portA Config Portb.5 = Input "switches on portB " Hardware Aliases (these tell bascom names we will use for I/O devices " attached to the Micro, names are easier to remember that ports) RedSw Alias Pinb.6 " hardware alias "---------------------------------------" Program starts here Do If Redsw = 0 Then "only do if switch pressed Toggle LED End If Loop End
We alter the program to wait a bit after the switch is pressed, which will give us time to release ithe switch “When the switch is pressed change the LED” "-----------------------------------------" Compiler Setup (these tell Bascom things about our micro) $regfile = "attiny461.dat" "bascom needs to know the micro $crystal = 1000000 "bascom needs to know its speed "----------------------------------------" Hardware Setups (these tell bascom how to setup our micro) " setup direction of all ports Config Porta = Output "LEDs on portA Config Portb.5 = Input "switches on portB " Hardware Aliases (these tell bascom names we will use for I/O devices " attached to the Micro, names are easier to remember that ports) RedSw Alias Pinb.6 " hardware alias "---------------------------------------" Program starts here Do If Redsw = 0Then " wait until switch press Toggle LED Waitms waitdelay End If Loop End
“If the switch is pressed, debounce the switch then toggle LED” "---------------------------------------" Compiler Setup (these tell Bascom things about our micro) $regfile = "attiny461.dat" "bascom needs to know the micro $crystal = 1000000 "bascom needs to know its speed "----------------------------------------" Hardware Setups (these tell bascom how to setup our micro) " setup direction of all ports Config Porta = Output "LEDs on portA Config Portb.5 = Input "switches on portB " Hardware Aliases (these tell bascom names we will use for I/O devices " attached to the Micro, names are easier to remember that ports) RedSw Alias Pinb.6 " hardware alias "---------------------------------------" Program starts here Do If Sw = 0 Then Waitms debouncetime Do Loop until Sw = 1 Waitms debouncetime Toggle Led End If Loop End
"-----------------------------------------------------------------" Title Block " Author: B.Collis " Date: 1 Aug 2008 " File Name: PedestrianCrossingLightsVer3.bas "-----------------------------------------------------------------" Program Description: " reads switch to check if pedestrian wants to cross " and changes the lights "-----------------------------------------------------------------" Compiler Setup (these tell Bascom things about our micro) $regfile = "attiny461.dat" "bascom needs to know the micro $crystal = 1000000 "bascom needs to know its speed "-----------------------------------------------------------------" Hardware Setups (these tell bascom how to setup our micro) " setup direction of all ports Config Porta = Output "LEDs on portA Config Portb = Input "switches on portB " Hardware Aliases (these tell bascom names we will use for I/O devices " attached to the Micro, names are easier to remember that ports) Greenlight Alias Porta.7 Orangelight Alias Porta.6 Redlight Alias Porta.5 Crossbutton Alias Pinb.6 Crossnowlight Alias Porta.3 Dontcrosslight Alias Porta.4 "-----------------------------------------------------------------" DIMENSION VARIABLES (a variable can be changed during the program, so we might have different delays at different times of the day (maybe before and after school we could change the orange and cross delay)
"----------------------------------------------" Compiler Setup $regfile = "attiny461.dat" $crystal = 1000000 "bascom needs to know its speed "-----------------------------------------------" Hardware Setups " setup direction of all ports Config Porta = Output "LEDs on portA Config Portb = Input "switches on portB " Hardware Aliases Green Alias Porta.1 Red Alias Porta.0 "-----------------------------------------------" Declare Constants Const Orangedelay = 7 Const Crossdelay = 20 Const Dontcrossdelay = 5 "----------------------------------------------" Program starts here "Declare Constants Const Lightontime = 500 Const Lightofftime = 2500 "---------------------------------------------"Declare Variables Dim Count As Byte "----------------------------------------------Program starts here Do For Count = 1 to 20 Set Red Waitms Lightontime Reset Red Waitms Lightofftime Incr Count Next For Count = 1 to 20 Set Green Waitms Lightontime Reset Green Waitms Lightofftime Incr Count Next Loop End
1.Type in the program COMPLETE THE MISSING PARTS, save it, Compile (F7) and Simulate it (F2). In the simulator window Step A: Choose the menu button with LCD, to open Hardware Simulation Step B: Select the switch inputs PinB.0 through PinB.4 as high (this simulates pullup resistors) Step C: Select the upper most blank yellow box in the variable area. Then double click it to get a drop down box. Then choose cars Do this for the 3 other variables
Variabes must start with a letter not a digit e.g. Dim Red_cars As Byte not Dim 1cars As Byte Variabes must not be Bascom reserved(special) words e.g. Dim band As Byte not Dim And As Byte Variables must contain no spaces e.g. Dim Red_cars As Byte not Dim Red cars As Byte Variable names should relate to what the variable is used for e.g. Dim Red_cars As Byte, not Dim hgashg As Byte Variable names cannot be used for other things such as constants or subroutines e.g. Dim Red_cars As Byte, means yu cannot have Const Red_cars = 12 as well
The simulator is an ideal tool for testing small parts of a program to see if you achieved what you wanted to. We will use it to explore the numerical range of different types of variables Here is some code to show off a few BASIC commands. Copy this program into BASCOM and compile it and see if you can understand what is happening and why. " ShowComandsV1.bas . $sim $crystal = 1000000 $regfile = "attiny26.dat" Config Porta = Output Config Portb = Output Config Pinb.6 = Input "dimension variables Dim Byte1 As Byte Dim Byte2 As Byte Dim Word1 As Word Dim Int1 As Integer Dim Single1 As Single Dim Single2 As Single
Every microcontroller has different amount of RAM available for storing variables Carry out research on these different AVR microcontrollers RAM size (bytes)
First lets review what a tone is. It is a repeated turning on and off of our piezo. The frequency of the tone is 1/period. The duration of the tone is the number of complete cycles. A piezo will not make a sound when you turn it on; it only makes a sound when you turn it on and off rapidly. So to make a tone we must turn the piezo on then wait a bit, then turn it off and we repeat this for the duration of the tone. In this program the tone period will be 1mS so the piezo must be on for 500uS (1/2 mS) and off for the same. Bascom has a waitus command (it is not particularly accurate but its good enough for this exercise). We want the tone to last long enough to hear it so we need to repeat it 150 times. 150 times 1mS will give us a tone duration of 150mS (0.15S). To count the number of cycles we will dimension a variable called cyclecount, and we will increase it inside a do-loop. It will count upto the max number of cycles and then we will have a 2 second break. Then it will repeat. Remember to reset cycle count to 0 or it will overflow. This program works similalrly to the Bascom SOUND command.
"-----------------------------------------------------------------" Title Block " Author: B.Collis " Date: 22 Feb 08 " File Name: SirenV1.bas "-----------------------------------------------------------------" Program Description: " This program makes a simple tone using a piezo " Program Features: " makes use of Bascom waitus (microseconds) command " introduces first use of a variable " the variable cyclecount increases from 0 until it reaches the preset (constant) " value maxcyclecount at which point there is a quiet time " the led is on when the the tone is occuring " Hardware Features " a pezo can be directly connected to the micro port " the led has a 1k resistor in series to limit the current "-----------------------------------------------------------------" Compiler Directives (these tell Bascom things about our hardware) $regfile = "attiny26.dat" "the micro we are using $crystal = 1000000 "rate of executing code "-----------------------------------------------------------------" Hardware Setups Config Portb = Output " Hardware Aliases Piezo Alias Portb.3 "use useful name PIEZO not PORTb.3 Blueled Alias Portb.4 "use useful name BLUELED not PORTB.4 "-----------------------------------------------------------------"Declare Constants Const Halfperioddelay = 500 " delay for 1/2 period Const Maxcyclecount = 150 "number of cycles to do "-----------------------------------------------------------------" Declare Variables Dim Cyclecount As Byte "-----------------------------------------------------------------" Program starts here Do Set Blueled "turn led on For Cyclecount = 0 to Maxcyclecount1 Waitus Halfperioddelay1 Set Piezo Waitus Halfperioddelay1 Reset Piezo Next Reset Blueled "turn led off Waitms 2000 "quiet time Loop End "end program
"-----------------------------------------------------------------" Title Block " Author: B.Collis " Date: 22 Feb 08 " File Name: SirenV2.bas "-----------------------------------------------------------------" Program Description: " This program makes a simple siren on a piezo " " Program Features: " makes use of bascom waitus (microseconds) command " Hardware Features: "-----------------------------------------------------------------" Compiler Directives (these tell Bascom things about our hardware) $crystal = 1000000 "the crystal we are using $regfile = "attiny26.dat" "the micro we are using "-----------------------------------------------------------------" Hardware Setups " setup direction of all ports Config Portb = Output " Hardware Aliases Piezo Alias Portb.3 "use useful name PIEZO not PORTb.3 Blueled Alias Portb.4 "use useful name BLUELED not PORTB.4 "-----------------------------------------------------------------"Declare Constants Const Halfperioddelay1 = 500 " first tone 1/2 period Const Halfperioddelay2 = 800 " second tone 1/2 period Const Maxcyclecount1 = 350 " longer than 255!!! Const Maxcyclecount2 = 150 "-----------------------------------------------------------------" Declare Variables Dim Cyclecount As Word "keep count of number of cycls(periods) Dim Sirens As Byte 175
it keeps the files that BASCOM generates for your program in one place this helps you find programs quickly when you want to it is less confusing it is good practice Save your program at the beginning when you start it, this helps guard against teachers that like to turn the computers off unexpectedly.
"-----------------------------------------------------------------" Compiler Directives (these tell Bascom things about our hardware) $regfile = "attiny26.dat" "the micro we are using $crystal = 1000000 "the speed of the micro "-----------------------------------------------------------------" Hardware Setups " setup direction of all ports Config Porta = Output "LEDs on portA Config Portb =Input "switches on portB " Hardware Aliases Led0 alias portb.0 " Initialise ports so hardware starts correctly Porta = &B11111111 "turns off LEDs "-----------------------------------------------------------------" Declare Variables " Initialise Variables " Declare Constants "-----------------------------------------------------------------" Program starts here Do Loop End<