|
|
(32 intermediate revisions by one user not shown) |
Line 1: |
Line 1: |
− | [[Category:BASCOM Language Reference]]
| + | <div id="idcontent"><div id="innerdiv"> |
− | <html> | + | = <span class="f_Header">Action</span><br/> = |
| | | |
| + | Send output to the UART. |
| | | |
− | <div id="idcontent"><div id="innerdiv">
| + | Writes a string to a file. |
| | | |
− | <p><span class="f_Header">Action</span></p>
| + | Writes data to a device. |
− | <p>Send output to the UART.</p>
| + | |
− | <p>Writes a string to a file.</p>
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
− | <p>Writes data to a device.</p>
| + | |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | |
− | <p><span class="f_Header">Syntax</span></p>
| + | = <span class="f_Header">Syntax</span><br/> = |
− | <p><span class="f_Syntax">PRINT</span> [#channel , ] var ; " constant"</p>
| + | |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | <span class="f_Syntax">PRINT</span> [#channel , ] var ; " constant" |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | |
− | <p><span class="f_Header">Remarks</span></p>
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
− | <div style="text-align: left; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 4px;"><table width="488" cellspacing="0" cellpadding="1" border="1" style="border: solid 1px #000000; border-spacing:0px;"> | + | |
− | <tr style="text-align:left;vertical-align:top;">
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
− | <td valign="top" width="11%" style="width:11%; border: solid 1px #000000;"><p>Var</p>
| + | |
− | </td>
| + | = <span class="f_Header">Remarks</span> = |
− | <td valign="top" width="100%" style="width:100%; border: solid 1px #000000;"><p>The variable or constant to print.</p>
| + | <div style="text-align: left; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 4px"> |
− | </td>
| + | {| style="border: solid 1px #000000; border-spacing:0px" border="1" cellpadding="1" cellspacing="0" width="488" |
− | </tr>
| + | |- style="text-align:left; vertical-align:top" |
− | </table>
| + | | style="width:11%; border: solid 1px #000000" valign="top" width="11%" | |
| + | Var |
| + | |
| + | | style="width:100%; border: solid 1px #000000" valign="top" width="100%" | |
| + | The variable or constant to print. |
| + | |
| + | |} |
| </div> | | </div> |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
− | <p>You can use a semicolon (<span style="font-weight: bold;">;</span>) to print multiple variables or constants after each other.</p>
| + | |
− | <p>When you end a line with a semicolon, no linefeed and carriage return will be added.</p>
| + | You can use a semicolon (<span style="font-weight: bold">;</span>) to print multiple variables or constants after each other. |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | |
− | <p>The PRINT routine can be used when you have a RS-232 interface on your processor.</p>
| + | When you end a line with a semicolon, no linefeed and carriage return will be added. |
− | <p>The RS-232 interface can be connected to a serial communication port of your computer.</p>
| + | |
− | <p>This way you can use a terminal emulator as an output device.</p>
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
− | <p>You can also use the build in terminal emulator.</p>
| + | |
− | <p>When using RS-485 you can use CONFIG PRINT to set up a pin for the direction.</p>
| + | The PRINT routine can be used when you have a RS-232 interface on your processor. |
− | <p>When printing arrays, you can only print one element at the time. When you need to print the content of a complete array, you need to use <a href="printbin.htm">PRINTBIN</a>.</p>
| + | |
− | <p> </p>
| + | The RS-232 interface can be connected to a serial communication port of your computer. |
− | <p>PRINT will automatic convert numeric variables into the string representation.</p>
| + | |
− | <p>This means that when you have a byte variable named B with the value of 123, the numeric variable is converted into a string "123" and then printed.</p>
| + | This way you can use a terminal emulator as an output device. |
− | <p>In this case, print will print 3 characters or bytes. When you want to print the byte you can use the chr() function : print chr(b);</p>
| + | |
− | <p>This will send just one byte to the UART.</p>
| + | You can also use the build in terminal emulator. |
− | <p> </p>
| + | |
− | <p>You can connect the processors UART (TX/RX pins) to a MAX232, an FTDI232RL, a Bluetooth module or a GPS modem. Always check the logic level vcc of the UART and the device you connect to. Connecting 5V devices to a 3v3 device might damage the 3v3 device. </p>
| + | When using RS-485 you can use CONFIG PRINT to set up a pin for the direction. |
− | <p>A serial port can be used to update firmware with a so called boot loader. </p>
| + | |
− | <p> </p>
| + | When printing arrays, you can only print one element at the time. When you need to print the content of a complete array, you need to use [[PRINTBIN]]. |
− | <p> </p>
| + | |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | |
− | <p><span class="f_Header">AVR-DOS</span></p>
| + | |
− | <p>The AVR-DOS file system also supports PRINT. But in that case, only strings can be written to disk.</p>
| + | PRINT will automatic convert numeric variables into the string representation. |
− | <p>When you need to print to the second hardware UART, or to a software UART, you need to specify a channel : PRINT <span style="font-weight: bold;">#1,</span> "test"</p>
| + | |
− | <p>The channel must be opened first before you can print to it. Look at <a href="open.htm">OPEN</a> and <a href="close.htm">CLOSE</a> for more details about the optional channel. For the first hardware UART, there is no need to use channels. The default for PRINT without a channel specifier, is the first UART.</p>
| + | This means that when you have a byte variable named B with the value of 123, the numeric variable is converted into a string "123" and then printed. |
− | <p>So : <span style="font-style: italic;">PRINT " test"</span> will always use the first hardware UART.</p>
| + | |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | In this case, print will print 3 characters or bytes. When you want to print the byte you can use the chr() function : print chr(b); |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | |
− | <p><span class="f_Header">Xmega-SPI</span></p>
| + | This will send just one byte to the UART. |
− | <p>When sending data to the SPI interface, you need to activate the SS pin. Some chips might need an active low, others might need an active high. This will depends on the slave chip.</p>
| + | |
− | <p>When you use the SS=AUTO option, the level of SS will be changed automatic. Thus SS is made low, then the data bytes are sent, and finally , SS is made high again. </p>
| + | |
− | <p> </p>
| + | |
− | <p>For SPI, no CRLF will be sent. Thus a trailing <span style="font-weight: bold;">;</span> is not needed. </p>
| + | You can connect the processors UART (TX/RX pins) to a MAX232, an FTDI232RL, a Bluetooth module or a GPS modem. Always check the logic level vcc of the UART and the device you connect to. Connecting 5V devices to a 3v3 device might damage the 3v3 device. |
− | <p> </p>
| + | |
− | <p><span class="f_Header">SPI Number of Bytes</span></p>
| + | A serial port can be used to update firmware with a so called boot loader. |
− | <p>The compiler will send 1 byte for variable which was dimensioned as a BYTE.</p>
| + | |
− | <p>It will send 2 bytes for a WORD/INTEGER, 4 bytes for a LONG/SINGLE and 8 bytes for a DOUBLE.</p>
| + | |
− | <p>As with all routines in BASCOM, the least significant Byte will be send first.</p>
| + | |
− | <p> </p>
| + | |
− | <p>When you send a numeric constant, the binary value will be sent : 123 will be send a 1 byte with the value of 123.</p>
| + | |
− | <p> </p>
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
− | <p>If you send an array element, one element will be send.</p>
| + | |
− | <p>With an optional parameter you can provide how many bytes must be sent. You must use a comma (,) to specify this parameter. This because the semi colon (;) is used to send multiple variables. </p>
| + | <span class="f_Header">AVR-DOS</span> |
− | <p> </p>
| + | |
− | <p><span class="f_Header">Sample</span></p>
| + | The AVR-DOS file system also supports PRINT. But in that case, only strings can be written to disk. |
− | <p>Dim Tmparray(5) As Byte , Spi_send_byte As Byte , W as Word </p>
| + | |
− | <p>Config Spid = Hard , Master = Yes , Mode = 0 , Clockdiv = Clk32 , Data_order = Msb , Ss = Auto</p>
| + | When you need to print to the second hardware UART, or to a software UART, you need to specify a channel : PRINT <span style="font-weight: bold">#1,</span> "test" |
− | <p>Open "SPID" For Binary As #12 </p>
| + | |
− | <p>Print #12 , Spi_send_byte ; W ' send ONE BYTE and 2 bytes of W</p>
| + | The channel must be opened first before you can print to it. Look at [[OPEN]] and [[CLOSE]] for more details about the optional channel. For the first hardware UART, there is no need to use channels. The default for PRINT without a channel specifier, is the first UART. |
− | <p>Print #12 , Tmparray(1) , 2 ' send 2 bytes of tmparray, starting at element 1</p>
| + | |
− | <p>Print #12 , Tmparray(1) ' send 1 byte</p>
| + | So : <span style="font-style: italic">PRINT " test"</span> will always use the first hardware UART. |
− | <p>Print #12 , Tmparray(3) , 2 ' send 2 bytes starting at index 3</p>
| + | |
− | <p>Print #12 , 123 ; 1000 ; Tmparray(1) , B ' send byte with value 123, 2 bytes with value 1000, and 'b' bytes of array</p>
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
− | <p> </p>
| + | |
− | <p> </p>
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
− | <p> </p>
| + | |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | <span class="f_Header">Xmega-SPI</span> |
− | <p><span class="f_Header">See also</span></p>
| + | |
− | <p><a href="input.htm">INPUT</a><a href="open.htm">,OPEN</a> , <a href="close.htm">CLOSE</a> , <a href="spc.htm">SPC</a> , <a href="printbin.htm">PRINTBIN</a> , <a href="hex.htm">HEX</a>, <a href="bin.htm">BIN</a></p>
| + | When sending data to the SPI interface, you need to activate the SS pin. Some chips might need an active low, others might need an active high. This will depends on the slave chip. |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | When you use the SS=AUTO option, the level of SS will be changed automatic. Thus SS is made low, then the data bytes are sent, and finally , SS is made high again. |
− | <p><span class="f_Header">Example</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; color: #008000;">'-----------------------------------------------------------------------------------------</span></p> | + | |
− | <p><span style="font-family: 'Courier New'; color: #008000;">'name : print.bas</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; color: #008000;">'copyright : (c) 1995-2005, MCS Electronics</span></p>
| + | For SPI, no CRLF will be sent. Thus a trailing <span style="font-weight: bold">;</span> is not needed. |
− | <p><span style="font-family: 'Courier New'; color: #008000;">'purpose : demo: PRINT, HEX</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; color: #008000;">'micro : Mega48</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; color: #008000;">'suited for demo : yes</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; color: #008000;">'commercial addon needed : no</span></p>
| + | <span class="f_Header">SPI Number of Bytes</span> |
− | <p><span style="font-family: 'Courier New'; color: #008000;">'-----------------------------------------------------------------------------------------</span></p>
| + | |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | The compiler will send 1 byte for variable which was dimensioned as a BYTE. |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">$regfile</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008080;">"m48def.dat"</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008000;">' specify the used micro</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">$crystal</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> 4000000 </span><span style="font-family: 'Courier New'; color: #008000;">' used crystal frequency</span></p>
| + | It will send 2 bytes for a WORD/INTEGER, 4 bytes for a LONG/SINGLE and 8 bytes for a DOUBLE. |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">$baud</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> 19200 </span><span style="font-family: 'Courier New'; color: #008000;">' use baud rate</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">$hwstack</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> 32 </span><span style="font-family: 'Courier New'; color: #008000;">' default use 32 for the hardware stack</span></p>
| + | As with all routines in BASCOM, the least significant Byte will be send first. |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">$swstack</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> 10 </span><span style="font-family: 'Courier New'; color: #008000;">' default use 10 for the SW stack</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">$framesize</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> 40 </span><span style="font-family: 'Courier New'; color: #008000;">' default use 40 for the frame space</span></p>
| + | |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Dim</span><span style="font-family: 'Courier New';"> A </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Byte</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">,</span><span style="font-family: 'Courier New';"> B1 </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Byte</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">,</span><span style="font-family: 'Courier New';"> C </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Integer</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">,</span><span style="font-family: 'Courier New';"> S </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">As</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">String</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">*</span><span style="font-family: 'Courier New';"> 4</span></p>
| + | When you send a numeric constant, the binary value will be sent : 123 will be send a 1 byte with the value of 123. |
− | <p><span style="font-family: 'Courier New';">A </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> 1</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008080;">"print variable a "</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">;</span><span style="font-family: 'Courier New';"> A</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008000;">'new line</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008080;">"Text to print."</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008000;">'constant to print</span></p>
| + | If you send an array element, one element will be send. |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | With an optional parameter you can provide how many bytes must be sent. You must use a comma (,) to specify this parameter. This because the semi colon (;) is used to send multiple variables. |
− | <p><span style="font-family: 'Courier New';">B1 </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> 10</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Hex</span><span style="font-family: 'Courier New'; color: #ff0000;">(</span><span style="font-family: 'Courier New';">b1</span><span style="font-family: 'Courier New'; color: #ff0000;">)</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008000;">'print in hexa notation</span></p>
| + | |
− | <p><span style="font-family: 'Courier New';">C </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">&</span><span style="font-family: 'Courier New';">HA000 </span><span style="font-family: 'Courier New'; color: #008000;">'assign value to c%</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Hex</span><span style="font-family: 'Courier New'; color: #ff0000;">(</span><span style="font-family: 'Courier New';">c</span><span style="font-family: 'Courier New'; color: #ff0000;">)</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008000;">'print in hex notation</span></p>
| + | = <span class="f_Header">Sample</span><br/> = |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> C </span><span style="font-family: 'Courier New'; color: #008000;">'print in decimal notation</span></p>
| + | |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | Dim Tmparray(5) As Byte , Spi_send_byte As Byte , W as Word |
− | <p><span style="font-family: 'Courier New';">C </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">-</span><span style="font-family: 'Courier New';">32000</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> C</span></p>
| + | Config Spid = Hard , Master = Yes , Mode = 0 , Clockdiv = Clk32 , Data_order = Msb , Ss = Auto |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Hex</span><span style="font-family: 'Courier New'; color: #ff0000;">(</span><span style="font-family: 'Courier New';">c</span><span style="font-family: 'Courier New'; color: #ff0000;">)</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; color: #008000;">Rem Note That Integers Range From -32767 To 32768</span></p>
| + | Open "SPID" For Binary As #12 |
− | <p><span style="font-family: 'Arial'; color: #000000;"> </span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008080;">"You can also use multiple"</span><span style="font-family: 'Courier New';"> _</span></p>
| + | Print #12 , Spi_send_byte ; W ' send ONE BYTE and 2 bytes of W |
− | <p><span style="font-family: 'Courier New'; color: #ff0000;">;</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008080;">"lines using _"</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008080;">"use it for long lines"</span></p>
| + | Print #12 , Tmparray(1) , 2 ' send 2 bytes of tmparray, starting at element 1 |
− | <p><span style="font-family: 'Courier New'; color: #008000;">'From version 1.11.6.4 :</span></p>
| + | |
− | <p><span style="font-family: 'Courier New';">A </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #ff0000;">&</span><span style="font-family: 'Courier New';">B1010_0111</span></p>
| + | Print #12 , Tmparray(1) ' send 1 byte |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Bin</span><span style="font-family: 'Courier New'; color: #ff0000;">(</span><span style="font-family: 'Courier New';">a</span><span style="font-family: 'Courier New'; color: #ff0000;">)</span></p>
| + | |
− | <p><span style="font-family: 'Courier New';">S </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; color: #008080;">"1001"</span></p>
| + | Print #12 , Tmparray(3) , 2 ' send 2 bytes starting at index 3 |
− | <p><span style="font-family: 'Courier New';">A </span><span style="font-family: 'Courier New'; color: #ff0000;">=</span><span style="font-family: 'Courier New';"> </span><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Binval</span><span style="font-family: 'Courier New'; color: #ff0000;">(</span><span style="font-family: 'Courier New';">s</span><span style="font-family: 'Courier New'; color: #ff0000;">)</span></p>
| + | |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">Print</span><span style="font-family: 'Courier New';"> A </span><span style="font-family: 'Courier New'; color: #008000;">'9 dec</span></p>
| + | Print #12 , 123 ; 1000 ; Tmparray(1) , B ' send byte with value 123, 2 bytes with value 1000, and 'b' bytes of array |
− | <p><span style="font-family: 'Courier New'; font-weight: bold; color: #000080;">End</span></p>
| + | |
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
| + | |
| + | = <span class="f_Header">See also</span><br/> = |
| + | |
| + | [[INPUT]] , [[OPEN]] , [[CLOSE]] , [[SPC]] , [[PRINTBIN]] , [[HEX]] , [[BIN]] |
| + | |
| + | <span style="font-family: 'Arial'; color: #000000"> </span> |
| + | |
| + | = <span class="f_Header">Example</span><br/> = |
| + | |
| + | <source lang="bascomavr"> |
| + | '----------------------------------------------------------------------------------------- |
| + | 'name : print.bas |
| + | 'copyright : (c) 1995-2005, MCS Electronics |
| + | 'purpose : demo: PRINT, HEX |
| + | 'micro : Mega48 |
| + | 'suited for demo : yes |
| + | 'commercial addon needed : no |
| + | '----------------------------------------------------------------------------------------- |
| + | |
| + | $regfile = "m48def.dat" ' specify the used micro |
| + | $crystal = 4000000 ' 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 |
| | | |
| | | |
− | </div></div>
| + | Dim A As Byte , B1 As Byte , C As Integer , S As String * 4 |
− | </html> | + | A = 1 |
− | <br /> | + | Print "print variable a " ; A |
− | <br /> | + | Print 'new line |
− | {{Languages}} | + | Print "Text to print." 'constant to print |
| + | |
| + | |
| + | B1 = 10 |
| + | Print Hex(b1) 'print in hexa notation |
| + | C = &HA000 'assign value to c% |
| + | Print Hex(c) 'print in hex notation |
| + | Print C 'print in decimal notation |
| + | |
| + | |
| + | C = -32000 |
| + | Print C |
| + | Print Hex(c) |
| + | Rem Note That Integers Range From -32767 To 32768 |
| + | |
| + | |
| + | Print "You can also use multiple" _ |
| + | ; "lines using _" |
| + | Print "use it for long lines" |
| + | 'From version 1.11.6.4 : |
| + | A = &B1010_0111 |
| + | Print Bin(a) |
| + | S = "1001" |
| + | A = Binval(s) |
| + | Print A '9 dec |
| + | End |
| + | |
| + | |
| + | </source> |
| + | <br/><br/>{{Languages}}</div></div> |
| + | [[Category:BASCOM Language Reference]] |
Send output to the UART.
Writes a string to a file.
Writes data to a device.
PRINT [#channel , ] var ; " constant"
Var
|
The variable or constant to print.
|
You can use a semicolon (;) to print multiple variables or constants after each other.
When you end a line with a semicolon, no linefeed and carriage return will be added.
The PRINT routine can be used when you have a RS-232 interface on your processor.
The RS-232 interface can be connected to a serial communication port of your computer.
This way you can use a terminal emulator as an output device.
You can also use the build in terminal emulator.
When using RS-485 you can use CONFIG PRINT to set up a pin for the direction.
When printing arrays, you can only print one element at the time. When you need to print the content of a complete array, you need to use PRINTBIN.
PRINT will automatic convert numeric variables into the string representation.
This means that when you have a byte variable named B with the value of 123, the numeric variable is converted into a string "123" and then printed.
In this case, print will print 3 characters or bytes. When you want to print the byte you can use the chr() function : print chr(b);
This will send just one byte to the UART.
You can connect the processors UART (TX/RX pins) to a MAX232, an FTDI232RL, a Bluetooth module or a GPS modem. Always check the logic level vcc of the UART and the device you connect to. Connecting 5V devices to a 3v3 device might damage the 3v3 device.
A serial port can be used to update firmware with a so called boot loader.
The AVR-DOS file system also supports PRINT. But in that case, only strings can be written to disk.
When you need to print to the second hardware UART, or to a software UART, you need to specify a channel : PRINT #1, "test"
The channel must be opened first before you can print to it. Look at OPEN and CLOSE for more details about the optional channel. For the first hardware UART, there is no need to use channels. The default for PRINT without a channel specifier, is the first UART.
So : PRINT " test" will always use the first hardware UART.
When sending data to the SPI interface, you need to activate the SS pin. Some chips might need an active low, others might need an active high. This will depends on the slave chip.
When you use the SS=AUTO option, the level of SS will be changed automatic. Thus SS is made low, then the data bytes are sent, and finally , SS is made high again.
For SPI, no CRLF will be sent. Thus a trailing ; is not needed.
The compiler will send 1 byte for variable which was dimensioned as a BYTE.
It will send 2 bytes for a WORD/INTEGER, 4 bytes for a LONG/SINGLE and 8 bytes for a DOUBLE.
As with all routines in BASCOM, the least significant Byte will be send first.
When you send a numeric constant, the binary value will be sent : 123 will be send a 1 byte with the value of 123.
If you send an array element, one element will be send.
With an optional parameter you can provide how many bytes must be sent. You must use a comma (,) to specify this parameter. This because the semi colon (;) is used to send multiple variables.
Dim Tmparray(5) As Byte , Spi_send_byte As Byte , W as Word
Config Spid = Hard , Master = Yes , Mode = 0 , Clockdiv = Clk32 , Data_order = Msb , Ss = Auto
Open "SPID" For Binary As #12
Print #12 , Spi_send_byte ; W ' send ONE BYTE and 2 bytes of W
Print #12 , Tmparray(1) , 2 ' send 2 bytes of tmparray, starting at element 1
Print #12 , Tmparray(1) ' send 1 byte
Print #12 , Tmparray(3) , 2 ' send 2 bytes starting at index 3
Print #12 , 123 ; 1000 ; Tmparray(1) , B ' send byte with value 123, 2 bytes with value 1000, and 'b' bytes of array
INPUT , OPEN , CLOSE , SPC , PRINTBIN , HEX , BIN
'-----------------------------------------------------------------------------------------
'name : print.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : demo: PRINT, HEX
'micro : Mega48
'suited for demo : yes
'commercial addon needed : no
'-----------------------------------------------------------------------------------------
$regfile = "m48def.dat" ' specify the used micro
$crystal = 4000000 ' 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
Dim A As Byte , B1 As Byte , C As Integer , S As String * 4
A = 1
Print "print variable a " ; A
Print 'new line
Print "Text to print." 'constant to print
B1 = 10
Print Hex(b1) 'print in hexa notation
C = &HA000 'assign value to c%
Print Hex(c) 'print in hex notation
Print C 'print in decimal notation
C = -32000
Print C
Print Hex(c)
Rem Note That Integers Range From -32767 To 32768
Print "You can also use multiple" _
; "lines using _"
Print "use it for long lines"
'From version 1.11.6.4 :
A = &B1010_0111
Print Bin(a)
S = "1001"
A = Binval(s)
Print A '9 dec
End