© MCS Electronics, 1995-2007
CONFIG PORT
Action
Sets the port or a port pin to the right data direction.
Syntax
CONFIG PORTx = state
CONFIG PINx.y = state
Remarks
state |
A numeric constant that can be INPUT or OUTPUT. |
|
INPUT will set the data direction register to input for port X. |
|
OUTPUT will set the data direction to output for port X. |
|
You can also use a number for state. &B0001111, wil set the upper |
|
nibble to input and the lower nibble to output. |
|
You can also set one port pin with the CONFIG PIN = state, |
|
statement. |
|
Again, you can use INPUT, OUTPUT or a number. In this case the |
|
number can be only zero or one. |
|
|
The best way to set the data direction for more than 1 pin, is to use the CONFIGPORT, statement and not multiple lines with CONFIG PIN statements.
Example
'----------------------------------------------------------------------------- |
|
------------ |
: port.bas |
'name |
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demo: PortB and PortD |
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'-----------------------------------------------------------------------------
------------
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 4000000 |
frequency |
' use baud rate |
$baud = 19200 |
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
for the SW stack |
' default use 40 |
$framesize = 40 |
for the frame space |
|
Dim A As Byte , Count As Byte |
|
'configure PORT D for input mode |
|
Config Portd = Input |
|
© MCS Electronics, 1995-2007
'reading the PORT, will read the latch, that is the value 'you have written to the PORT.
'This is not the same as reading the logical values on the pins! 'When you want to know the logical state of the attached hardware, 'you MUST use the PIN register.
A = Pind
'a port or SFR can be treated as a byte A = A And Portd
Print A |
'print it |
Bitwait Pind.7 , Reset |
'wait until bit is |
low |
|
'We will use port B for output |
|
Config Portb = Output |
|
'assign value |
'set port B to 10 |
Portb = 10 |
Portb = Portb And 2 |
|
Set Portb.0 |
'set bit 0 of port |
B to 1 |
|
Incr Portb |
|
'Now a light show on the STK200 |
|
Count = 0 |
|
Do |
|
|
Incr Count |
|
|
Portb = 1 |
|
|
For A = 1 To 8 |
'rotate bits left |
|
Rotate Portb , Left |
|
Wait 1 |
|
|
Next |
|
|
'the following 2 lines do the same as the previous loop |
|
' |
'but there is no delay |
|
Portb = 1 |
|
' |
Rotate Portb , Left , 8 |
|
Loop Until Count = 10 |
|
Print "Ready" |
|
'Again, note that the AVR port pins have a data direction register 'when you want to use a pin as an input it must be set low first 'you can do this by writing zeros to the DDRx:
'DDRB =&B11110000 'this will set portb1.0,portb.1,portb.2 and portb.3 to use as inputs.
'So : when you want to use a pin as an input set it low first in the DDRx!
'and read with PINx
'and when you want to use the pin as output, write a 1 first
'and write the value to PORTx
End
CONFIG PRINT
Action
Configure the UART to be used for RS-485
© MCS Electronics, 1995-2007
Syntax
CONFIG PRINT0 = pin
CONFIG PRINT1 = pin
Remarks
pin |
The name of the PORT pin that is used to control the |
|
direction of an RS-485 driver. |
mode |
SET or RESET |
|
|
Use PRINT or PRINT0 for the first serial port. Use PRINT1 for the second serial port.
When you use RS-485 half duplex communication you need a pin for the direction of the data. The CONFIG PRINT automates the manual setting/resetting. It will either SET or RESET the logic level of the specified pin before data is printed with the BASCOM print routines. After the data is sent, it will inverse the pin so it goes into receive mode.
You need to set the direction of the used pin to outputmode yourself.
See also
CONFIG PRINTBIN
Example
'------------------------------------------------------------------------------
'name |
:rs485.bas |
'copyright |
: (c) 1995-2006, MCS Electronics |
'purpose |
: demonstrates |
'micro |
:Mega48 |
'suited for demo |
: yes |
: no |
'commercial addon needed |
'------------------------------------------------------------------------------ |
|
' we use the M48 |
$regfile= "m48def.dat" |
$crystal= 8000000 |
|
|
$baud = 19200 |
|
|
$hwstack= 32 |
|
|
$swstack= 32 |
|
|
$framesize = 32 |
|
|
Config Print0= Portb.0 ,Mode = Set |
Config Pinb.0 = Output |
'set the direction yourself |
Dim Resp As String* 10 |
|
Do |
|
|
Print"test message" |
' get response |
Input Resp |
|
Loop |
|
|
CONFIG PRINTBIN
© MCS Electronics, 1995-2007
Action
Configure PRINTBIN behavior
Syntax
CONFIG PRINTBIN = extended
Remarks
extended |
This mode is the only mode. It allows to send huge |
|
arrays(more then 255 elements) to the serial port. |
|
Without the CONFIG PRINTBIN option, the maximum |
|
number of elements is 255. Because support for big |
|
arrays cost more code, it is made optional. |
|
|
See also
CONFIG PRINT
Example
$regfile = "m103def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 8000000 |
frequency |
' use baud rate |
$baud = 19200 |
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
for the SW stack |
' default use 40 |
$framesize = 40 |
for the frame space |
|
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Printbin = Extended
Dim A(1000)
Printbin A(1) ; 1000
CONFIG PS2EMU
Action
Configures the PS2 mouse data and clock pins.
Syntax
CONFIG PS2EMU= int , DATA = data, CLOCK=clock
Remarks
Int |
The interrupt used such as INT0 or INT1. |
|
|
|
|
© MCS Electronics, 1995-2007 |
|
|
|
|
|
|
DATA |
The pin that is connected to the DATA line. This must be the same pin as |
|
|
the used interrupt. |
|
|
|
CLOCK |
The pin that is connected to the CLOCK line. |
|
|
|
|
|
|
|
|
|
5-pin DIN |
|
|
|
|
|
(AT/XT): |
|
|
|
|
1 |
- Clock |
|
|
|
|
2 |
- Data |
|
|
|
|
3 |
- Not |
|
|
|
|
Implemented |
|
|
|
|
4 |
- Ground |
|
|
|
|
5 |
- +5v |
|
|
|
|
|
|
|
|
6-pin Mini-DIN (PS/2):
1 - Data
2 - Not Implemented 3 - Ground 4 - +5v
5 - Clock
6 - Not Implemented
Old PC’s are equipped with a 5-pin DIN female connector. Newer PC’s have a 6-pin mini DIN female connector.
The male sockets must be used for the connection with the micro.
Besides the DATA and CLOCK you need to connect fromthe PC to the micro, you need to connect ground. You can use the +5V from the PC to power your microprocessor.
The config statement will setup an ISR that is triggered when the INT pin goes low. This routine you can find in the library.
The ISR will retrieve a byte from the PC and will send the proper commands back to the PC.
The SENDSCAN and PS2MOUSEXY statements allow you to send mouse commands.
Note that the mouse emulator is only recognized after you have booted your PC. Mouse devices can not be plugged into your PC once it has booted. Inserting a mouse or mouse device when the PC is already booted, may damage your PC.
See also
SENDSCAN, PS2MOUSEXY
Example
'----------------------------------------------------------------------------- |
|
------------ |
: ps2_emul.bas |
'name |