Tips and tricks
(Created page with "This section describes tips and tricks received from users. <span style="font-family: Arial;"> </span> <span style="font-family: Arial;"> </span> Kyle Kronyak&nbs...") |
|||
(One intermediate revision by one user not shown) | |||
Line 1: | Line 1: | ||
− | + | <span style="font-size: 14pt; font-weight: bold;">Tips & Tricks:</span> | |
− | + | | |
− | <span | + | <span class="f_Header">1. You can specify a binary number with the &B and you can use underscore "_" like:</span> |
− | + | <span class="f_Header"> </span> | |
− | <span style="font-family: | + | <span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> Var </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Byte</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New';">Var </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">&</span><span style="font-family: 'Courier New';">B00_110000</span><br/><span style="font-family: 'Courier New';">Var </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">&</span><span style="font-family: 'Courier New';">B0000_1111</span><br/><span style="font-family: 'Courier New';">Var </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">&</span><span style="font-family: 'Courier New';">B00_11_00_11</span> |
− | + | <span style="font-size: 8pt; font-family: Courier;"> </span> | |
− | <span style="font-family: | + | <span style="font-size: 8pt; font-family: Courier;"> </span> |
− | <span | + | <span class="f_Header">2. How to use longer formulas:</span> |
− | + | <span style="font-size: 12pt; font-family: 'Times New Roman';"> </span> | |
− | <span style="font-family: | + | <span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> A </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Byte</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> B </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Byte</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> C </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Byte</span><br/><span style="font-family: Courier;"> </span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Now you want to use following formula: a = B / 4 + C</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' In Bascom you write</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New';">A </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> B </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">/</span><span style="font-family: 'Courier New';"> 4</span><br/><span style="font-family: 'Courier New';">A </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> A </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">+</span><span style="font-family: 'Courier New';"> C</span> |
− | - | + | <span style="font-size: 8pt; font-family: Courier;"> </span> |
+ | |||
+ | <span style="font-size: 8pt; font-family: Courier;"> </span> | ||
+ | |||
+ | <span class="f_Header">3. You can use more than one Bascom statement in one line with colons ":"</span> | ||
+ | |||
+ | <span style="font-size: 8pt; font-family: Courier;"> </span> | ||
+ | |||
+ | <span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> A </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Byte</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> B </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Byte</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> C </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Byte</span><br/><span style="font-size: 11pt; font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Now you want to use following formula: a = B / 4 + C</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' In Bascom you write</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New';">A </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> B </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">/</span><span style="font-family: 'Courier New';"> 4 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">:</span><span style="font-family: 'Courier New';"> A </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> A </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">+</span><span style="font-family: 'Courier New';"> C</span> | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | + | <span class="f_Header">4. You can use overlay to have easy access to the low byte and high byte of a WORD</span> | |
+ | |||
+ | <span class="f_Header">(the same approach also work for e.g. LONG)</span> | ||
+ | |||
+ | | ||
+ | |||
+ | <span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> My_word </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Word</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> Low_byte </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Byte</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">At</span><span style="font-family: 'Courier New';"> My_word </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Overlay</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> High_byte </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Byte</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">At</span><span style="font-family: 'Courier New';"> My_word </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">+</span><span style="font-family: 'Courier New';"> 1 </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Overlay</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New';">Low_byte </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">&</span><span style="font-family: 'Courier New';">B0000_1111</span><br/><span style="font-family: 'Courier New';">High_byte </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">&</span><span style="font-family: 'Courier New';">B1111_0000</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' This is how it will be stored in SRAM</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' <-------my_word--------></span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' +-----------+----------+</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' | Low_byte |High_byte |</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' +-----------+----------+</span> | ||
+ | |||
+ | <span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 128, 0);"> </span> | ||
+ | |||
+ | <span style="font-size: 8pt; font-family: Courier; color: rgb(0, 128, 0);"> </span> | ||
+ | |||
+ | <span class="f_Header">5. To split a word into High byte and Low byte</span> you can also use <a _fcknotitle="true" href="HIGH">HIGH</a> and <a _fcknotitle="true" href="LOW">LOW</a> | ||
+ | |||
+ | | ||
+ | |||
+ | <span class="f_Header">6. Here is a way to print the content of a variable or AVR register:</span> | ||
+ | |||
+ | | ||
+ | |||
+ | Use <span style="font-size: 11pt; font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Print</span><span style="font-size: 11pt; font-family: 'Courier New';"> </span><span style="font-size: 11pt; font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Bin</span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(255, 0, 0);">(X)</span> | ||
+ | |||
+ | | ||
+ | |||
+ | Example: | ||
+ | |||
+ | | ||
+ | |||
+ | <span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$regfile</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 128);">"m88def.dat"</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' we use the M88</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$crystal</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 8000000</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$baud</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 19200</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$hwstack</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 32</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$swstack</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 8</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$framesize</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 24</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Dim</span><span style="font-family: 'Courier New';"> A </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Byte</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New';">A </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">&</span><span style="font-family: 'Courier New';">B00000001</span><br/><span style="font-family: 'Courier New';">A </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> A </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">*</span><span style="font-family: 'Courier New';"> 2</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Bin</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">(</span><span style="font-family: 'Courier New';">a</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">) </span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">End</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' end program</span> | ||
+ | |||
+ | <span style="font-size: 8pt; font-family: Courier; color: rgb(0, 128, 0);"> </span> | ||
+ | |||
+ | <span style="font-size: 8pt; font-family: Courier; color: rgb(0, 128, 0);"> </span> | ||
+ | |||
+ | <span class="f_Header">7. If you do not want that Bascom-AVR is sending Carriage + Return after a print command use semi-colon ";" after the print funtion:</span> | ||
+ | |||
+ | | ||
+ | |||
+ | Example: | ||
+ | |||
+ | | ||
+ | |||
+ | <span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$regfile</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 128);">"m88def.dat"</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' specify the used micro</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$crystal</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 8000000 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' used crystal frequency</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$baud</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 19200 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' use baud rate</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$hwstack</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 32 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' default use 32 for the hardware stack</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$swstack</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 10 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' default use 10 for the SW stack</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$framesize</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 40 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' default use 40 for the frame space</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> Com1 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> Dummy </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">,</span><span style="font-family: 'Courier New';"> Synchrone </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 0 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">,</span><span style="font-family: 'Courier New';"> Parity </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> None </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">,</span><span style="font-family: 'Courier New';"> Stopbits </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 1 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">,</span><span style="font-family: 'Courier New';"> Databits </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 8 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">,</span><span style="font-family: 'Courier New';"> Clockpol </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 0</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 128);">"Hello World"</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">;</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">End</span> | ||
+ | |||
+ | <span style="font-size: 11pt; font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);"> </span> | ||
+ | |||
+ | <span style="font-size: 8pt; font-family: Courier; color: rgb(0, 128, 0);"> </span> | ||
+ | |||
+ | <span class="f_Header">8. For the user who want to use external editors:</span> | ||
+ | |||
+ | | ||
+ | |||
+ | The <span style="font-weight: bold;">bascomp.exe</span> has been updated. It can be downloaded from the download section. | ||
+ | |||
+ | | ||
+ | |||
+ | It now supports a simpler way to be called. | ||
+ | |||
+ | | ||
+ | |||
+ | The utility has been updated and now will retrieve all info from the source file, but only when your main program contains these directive : | ||
+ | |||
+ | $regfile, $hwstack, $swstack, $framesize | ||
+ | |||
+ | | ||
+ | |||
+ | <span style="font-weight: bold;">Example :</span> | ||
+ | |||
+ | bascomp.exe "c:\my folder\source\sample.bas" auto | ||
+ | |||
+ | | ||
+ | |||
+ | The 'auto' is a switch so the utility will retrieve the settings from your code. | ||
+ | |||
+ | | ||
+ | |||
+ | <span class="f_Header">9. You can use $initmicro if you want to run special tasks at startup:</span> | ||
+ | |||
+ | See <a _fcknotitle="true" href="%24INITMICRO">$INITMICRO</a> | ||
+ | |||
+ | | ||
+ | |||
+ | <span class="f_Header">10. You can use $include </span><span class="f_Header">to make larger projects better readable</span>: See <span style="font-size: 12pt; font-family: 'Times New Roman';"><a _fcknotitle="true" href="%24INCLUDE">$INCLUDE</a></span> | ||
+ | |||
+ | | ||
+ | |||
+ | <span class="f_Header">11. Your LCD is not working and you need a list of steps what do check:</span> | ||
+ | |||
+ | | ||
+ | |||
+ | a. Check fuse bit settings | ||
+ | |||
+ | b. Are the AVR pins are OK ? | ||
+ | |||
+ | | ||
+ | |||
+ | To test the AVR pins you can do following: | ||
+ | |||
+ | Write a program that toggles all the lcd pins and then measure the logic level. | ||
+ | |||
+ | Then check with a DVM or led-series resistor if all pins change level. if they do, there is a problem with the lcd | ||
+ | |||
+ | | ||
+ | |||
+ | If the pin do not toggle: | ||
+ | |||
+ | - pin defect | ||
+ | |||
+ | - track or solder problem. | ||
+ | |||
+ | | ||
+ | |||
+ | Here the test program: | ||
+ | |||
+ | | ||
+ | |||
+ | <span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$regfile</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 128);">"m328pdef.dat"</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Specify The Used Micro</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$crystal</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 16000000 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' used crystal frequency</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$baud</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 19200 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' use baud rate</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$hwstack</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 32 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' default use 32 for thehardware stack</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$swstack</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 10 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' default use 10 for theSW stack</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$framesize</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 40 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' default use 40 for theframe space</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> Clockdiv </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 1 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' divide xtal clock by 1, default fuse bit is set ' to 8 by elektor</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portc</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">3 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Output</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' RW</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portd</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">4 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Output</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Db4</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portd</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">5 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Output</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Db5</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portd</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">6 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Output</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Db6</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portd</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">6 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Output</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Db7</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portc</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">1 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Output</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' E</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portc</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">2 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Output</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' RS</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">do</span><br/><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">toggle</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">portc</span><br/><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">toggle</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">portd</span><br/><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">waitms</span><span style="font-family: 'Courier New';"> 1000</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Loop</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">End</span><span style="font-family: 'Courier New';"> </span><span style="font-size: 11pt; font-family: 'Courier New';"> </span><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(0, 128, 0);">' end program</span> | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | <span class="f_Header">12. With the Lib Manager you can compile a Library (*.lib) into an *.lbx file.</span> | ||
+ | |||
+ | See here: <a href="Tools%20LIB%20Manager">Tools LIB Manager</a> | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | <span class="f_Header">13. There is a timeout function for hardware and software UART</span> | ||
+ | |||
+ | See <a _fcknotitle="true" href="%24TIMEOUT">$TIMEOUT</a> | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | <span class="f_Header">14. How to use the Powerdown function:</span> | ||
+ | |||
+ | See also: <a href="CONFIG%20POWERMODE">CONFIG POWERMODE</a> | ||
+ | |||
+ | <span style="font-size: 8pt; font-family: Courier;"> </span> | ||
+ | |||
+ | If you can not measure the same power down current as written in the data sheet you also need to use a | ||
+ | |||
+ | Low Quiescent Current LDO Regulator to meet that specs (if you measure the current including the Current LDO Regulator). | ||
+ | |||
+ | | ||
+ | |||
+ | Examples for 3.3Volt Low Quiescent Current LDO Regulator : | ||
+ | <div style="padding: 0px; margin: 0px 0px 0px 24px;"> | ||
+ | {| border="0" cellpadding="0" cellspacing="0" | ||
+ | |- valign="baseline" style="vertical-align: baseline;" | ||
+ | | width="13" | <span style="font-size: 10pt; font-family: 'Arial Unicode MS', 'Lucida Sans Unicode', Arial;">•</span> | ||
+ | | MCP1702 --> typical 2µA | ||
+ | |} | ||
+ | </div><div style="padding: 0px; margin: 0px 0px 0px 24px;"> | ||
+ | {| border="0" cellpadding="0" cellspacing="0" | ||
+ | |- valign="baseline" style="vertical-align: baseline;" | ||
+ | | width="13" | <span style="font-size: 10pt; font-family: 'Arial Unicode MS', 'Lucida Sans Unicode', Arial;">•</span> | ||
+ | | MCP1700 --> typical 1.6µA | ||
+ | |} | ||
+ | </div><div style="padding: 0px; margin: 0px 0px 0px 24px;"> | ||
+ | {| border="0" cellpadding="0" cellspacing="0" | ||
+ | |- valign="baseline" style="vertical-align: baseline;" | ||
+ | | width="13" | <span style="font-size: 10pt; font-family: 'Arial Unicode MS', 'Lucida Sans Unicode', Arial;">•</span> | ||
+ | | AS1375 low power LDO --> 1µA (typ.) of quiescent current | ||
+ | |} | ||
+ | </div><div style="padding: 0px; margin: 0px 0px 0px 24px;"> | ||
+ | {| border="0" cellpadding="0" cellspacing="0" | ||
+ | |- valign="baseline" style="vertical-align: baseline;" | ||
+ | | width="13" | <span style="font-size: 10pt; font-family: 'Arial Unicode MS', 'Lucida Sans Unicode', Arial;">•</span> | ||
+ | | TPS78233 3,3V --> 0.4µA | ||
+ | |} | ||
+ | </div> | ||
+ | <br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Using the new config powermode = PowerDown function with ATTINY13</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Used Bascom-AVR Version 2.0.7.3</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Fuse Bits:</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Disable DWEN (Debug Wire) Fuse Bit</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Disable Brown-Out Detection in Fuse Bits</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Disable Watchdog in Fuse Bits</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' You can also just use Config Powermode = Powerdown</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' But this example here also considers what the data sheet write under "MINIMIZING POWER CONSUMPTION"</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' You need to follow this when you want to achieve the current consumption which you find in the</span> | ||
+ | |||
+ | <span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' data sheet under Powerdown Mode.</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' 1. Disable/Switch off ADC</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' 2. Disable/Switch off Analog Comparator</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' 3. Disable Brown-out Detection when not needed</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' 4. Disable internal voltage reference</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' 5. Disable Watchdog Timer when not needed</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' 6. Disable the digital input buffer</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' 7. Enable Pull-up or pull-down an all unused pins</span><br/><span style="font-size: 11pt; font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$regfile</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 128);">"attiny13.dat"</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$crystal</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 9600000 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' 9.6MHz</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$hwstack</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 10</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$swstack</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 0</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">$framesize</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> 24</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">On</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Int0</span><span style="font-family: 'Courier New';"> Int0_isr </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' INT0 will be the wake-up source for Powerdown Mode</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Int0</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Low</span><span style="font-family: 'Courier New';"> Level</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Enable</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Int0</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Prepare Powerdown:</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' To minimize power consumption, enable pull-up or -down on all unused pins, and</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' disable the digital input buffer on pins that are connected to analog sources</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portb</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">0 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Input</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Set</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portb</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">0</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portb</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">1 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Input</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' INT0 --> external 47K pull-up</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">'Set Portb.1</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portb</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">2 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Input</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Set</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portb</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">2</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portb</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">3 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Input</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Set</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portb</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">3</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portb</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">4 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Input</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Set</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portb</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">4</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Portb</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New';">5 </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Input</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' External Pull-Up (Reset)</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Didr0</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Bits</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">(</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">ain1d</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">,</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Ain0d</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">)</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Disable digital input buffer on the AIN1/0 pin</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Set</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Acsr</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">acd</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Switch off the power to the Analog Comparator</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' alternative:</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Stop Ac</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Reset</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Acsr</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">acbg</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Disable Analog Comparator Bandgap Select</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Reset</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">Adcsra</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">.</span><span style="font-family: 'Courier New'; color: rgb(128, 0, 0);">aden</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Switch off ADC</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' alternative:</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Stop Adc</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">'###############################################################################</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Do</span><br/> <span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Wait</span><span style="font-family: 'Courier New';"> 3 </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' now we have 3 second to measure the Supply Current</span> | ||
+ | |||
+ | <span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' in Active Mode</span><br/><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Enable</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Interrupts</span><br/><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Now call Powerdown function</span><br/><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Config</span><span style="font-family: 'Courier New';"> Powermode </span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Powerdown</span> | ||
+ | |||
+ | <span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' Here you have time to measure PowerDown current consumption until a Low Level</span> | ||
+ | |||
+ | <span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' on Portb.1 which is the PowerDown wake-up</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Loop</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">'###############################################################################</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">End</span><br/><span style="font-family: 'Courier New';"> </span><br/><span style="font-family: 'Courier New';">Int0_isr</span><span style="font-family: 'Courier New'; color: rgb(255, 0, 0);">:</span><br/><span style="font-family: 'Courier New'; color: rgb(0, 128, 0);">' wake_up</span><br/><span style="font-family: 'Courier New'; font-weight: bold; color: rgb(0, 0, 128);">Return</span> | ||
+ | |||
+ | |||
− | + | {{Languages}} | |
− | [[Category: | + | [[Category:BASCOM_Language_Fundamentals]] |
Latest revision as of 21:22, 24 August 2013
Tips & Tricks:
1. You can specify a binary number with the &B and you can use underscore "_" like:
Dim Var As Byte
Var = &B00_110000
Var = &B0000_1111
Var = &B00_11_00_11
2. How to use longer formulas:
Dim A As Byte
Dim B As Byte
Dim C As Byte
' Now you want to use following formula: a = B / 4 + C
' In Bascom you write
A = B / 4
A = A + C
3. You can use more than one Bascom statement in one line with colons ":"
Dim A As Byte
Dim B As Byte
Dim C As Byte
' Now you want to use following formula: a = B / 4 + C
' In Bascom you write
A = B / 4 : A = A + C
4. You can use overlay to have easy access to the low byte and high byte of a WORD
(the same approach also work for e.g. LONG)
Dim My_word As Word
Dim Low_byte As Byte At My_word Overlay
Dim High_byte As Byte At My_word + 1 Overlay
Low_byte = &B0000_1111
High_byte = &B1111_0000
' This is how it will be stored in SRAM
' <-------my_word-------->
' +-----------+----------+
' | Low_byte |High_byte |
' +-----------+----------+
5. To split a word into High byte and Low byte you can also use <a _fcknotitle="true" href="HIGH">HIGH</a> and <a _fcknotitle="true" href="LOW">LOW</a>
6. Here is a way to print the content of a variable or AVR register:
Use Print Bin(X)
Example:
$regfile = "m88def.dat" ' we use the M88
$crystal = 8000000
$baud = 19200
$hwstack = 32
$swstack = 8
$framesize = 24
Dim A As Byte
A = &B00000001
A = A * 2
Print Bin(a)
End ' end program
7. If you do not want that Bascom-AVR is sending Carriage + Return after a print command use semi-colon ";" after the print funtion:
Example:
$regfile = "m88def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Print "Hello World" ;
End
8. For the user who want to use external editors:
The bascomp.exe has been updated. It can be downloaded from the download section.
It now supports a simpler way to be called.
The utility has been updated and now will retrieve all info from the source file, but only when your main program contains these directive :
$regfile, $hwstack, $swstack, $framesize
Example :
bascomp.exe "c:\my folder\source\sample.bas" auto
The 'auto' is a switch so the utility will retrieve the settings from your code.
9. You can use $initmicro if you want to run special tasks at startup:
See <a _fcknotitle="true" href="%24INITMICRO">$INITMICRO</a>
10. You can use $include to make larger projects better readable: See <a _fcknotitle="true" href="%24INCLUDE">$INCLUDE</a>
11. Your LCD is not working and you need a list of steps what do check:
a. Check fuse bit settings
b. Are the AVR pins are OK ?
To test the AVR pins you can do following:
Write a program that toggles all the lcd pins and then measure the logic level.
Then check with a DVM or led-series resistor if all pins change level. if they do, there is a problem with the lcd
If the pin do not toggle:
- pin defect
- track or solder problem.
Here the test program:
$regfile = "m328pdef.dat" ' Specify The Used Micro
$crystal = 16000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for thehardware stack
$swstack = 10 ' default use 10 for theSW stack
$framesize = 40 ' default use 40 for theframe space
Config Clockdiv = 1 ' divide xtal clock by 1, default fuse bit is set ' to 8 by elektor
Config Portc.3 = Output ' RW
Config Portd.4 = Output ' Db4
Config Portd.5 = Output ' Db5
Config Portd.6 = Output ' Db6
Config Portd.6 = Output ' Db7
Config Portc.1 = Output ' E
Config Portc.2 = Output ' RS
do
toggle portc
toggle portd
waitms 1000
Loop
End ' end program
12. With the Lib Manager you can compile a Library (*.lib) into an *.lbx file.
See here: <a href="Tools%20LIB%20Manager">Tools LIB Manager</a>
13. There is a timeout function for hardware and software UART
See <a _fcknotitle="true" href="%24TIMEOUT">$TIMEOUT</a>
14. How to use the Powerdown function:
See also: <a href="CONFIG%20POWERMODE">CONFIG POWERMODE</a>
If you can not measure the same power down current as written in the data sheet you also need to use a
Low Quiescent Current LDO Regulator to meet that specs (if you measure the current including the Current LDO Regulator).
Examples for 3.3Volt Low Quiescent Current LDO Regulator :
• | MCP1702 --> typical 2µA |
• | MCP1700 --> typical 1.6µA |
• | AS1375 low power LDO --> 1µA (typ.) of quiescent current |
• | TPS78233 3,3V --> 0.4µA |
' Using the new config powermode = PowerDown function with ATTINY13
' Used Bascom-AVR Version 2.0.7.3
' Fuse Bits:
' Disable DWEN (Debug Wire) Fuse Bit
' Disable Brown-Out Detection in Fuse Bits
' Disable Watchdog in Fuse Bits
' You can also just use Config Powermode = Powerdown
' But this example here also considers what the data sheet write under "MINIMIZING POWER CONSUMPTION"
' You need to follow this when you want to achieve the current consumption which you find in the
' data sheet under Powerdown Mode.
' 1. Disable/Switch off ADC
' 2. Disable/Switch off Analog Comparator
' 3. Disable Brown-out Detection when not needed
' 4. Disable internal voltage reference
' 5. Disable Watchdog Timer when not needed
' 6. Disable the digital input buffer
' 7. Enable Pull-up or pull-down an all unused pins
$regfile = "attiny13.dat"
$crystal = 9600000 ' 9.6MHz
$hwstack = 10
$swstack = 0
$framesize = 24
On Int0 Int0_isr ' INT0 will be the wake-up source for Powerdown Mode
Config Int0 = Low Level
Enable Int0
' Prepare Powerdown:
' To minimize power consumption, enable pull-up or -down on all unused pins, and
' disable the digital input buffer on pins that are connected to analog sources
Config Portb.0 = Input
Set Portb.0
Config Portb.1 = Input ' INT0 --> external 47K pull-up
'Set Portb.1
Config Portb.2 = Input
Set Portb.2
Config Portb.3 = Input
Set Portb.3
Config Portb.4 = Input
Set Portb.4
Config Portb.5 = Input ' External Pull-Up (Reset)
Didr0 = Bits(ain1d , Ain0d) ' Disable digital input buffer on the AIN1/0 pin
Set Acsr.acd ' Switch off the power to the Analog Comparator
' alternative:
' Stop Ac
Reset Acsr.acbg ' Disable Analog Comparator Bandgap Select
Reset Adcsra.aden ' Switch off ADC
' alternative:
' Stop Adc
'###############################################################################
Do
Wait 3 ' now we have 3 second to measure the Supply Current
' in Active Mode
Enable Interrupts
' Now call Powerdown function
Config Powermode = Powerdown
' Here you have time to measure PowerDown current consumption until a Low Level
' on Portb.1 which is the PowerDown wake-up
Loop
'###############################################################################
End
Int0_isr:
' wake_up
Return
Languages | English • Deutsch |
---|