Data is read or written to the ports by reading or writing the Rx (RA, RB, RC, etc... No "!" in front) registers. Yes, you can use clrb and setb, but don't! At 75Mhz, Read/Modify/Write problems are no small thing. RMW problems get worse at higher speeds and also get worse at lower voltages.
For example mov RA,w will move the data from the working register to the RA port. However, the ports are multipurpose: They can be input ports, output ports, support TTL or CMOS logic levels and many other options exist. These are selected via the port control registers.
The MODE register serves as an index to all port control registers. The control registers for the ports are denoted as !Rx (!RA, !RB, or !RC, like the actual data ports but with a "!" in front) but writing to !RA may set the input/output configuration or the TTL/CMOS, or the pull-up/hi-z configuration, etc... depending on the setting of the MODE register.
In order to write or read any ports control register, the MODE register must contain the appropriate value to point to that port register. The W register is used to write into the MODE register.
The format of the MODE register is shown below. The four least significant bits serve as the pointer to the set of port registers to be accessed. Upon reset, the MODE register is initialized to 0Fh in the SX18 and 28 and to 1Fh in the SX48 and 52. In this default configuration, the program can write the !RA, !RB, and !RC (data direction) registers.
|bit 7||bit 0|
In order for the program to gain access to the other port control registers (to set the pullup resistor, input voltage levels, Schmitt triggers, etc.), the program must write a different value into the MODE register. The mov m,w command will actually exchange the value of the register with w, allowing the program to know the previous state of the port control register. This is how the MODE register controls access to the port registers in the SX18/28:
DIR (aka TRIS) Mode = xF writing to !RA, !RB or !RC will affect the direction of the port pins. A 1 will set that port pin to an input. A 0 will set it to an output
PLP: Mode = xE writing to !RA, !RB or !RC will affect the use of the weak pullup resister on this port. A 1 will disable it and a 0 will enable it.
LVL: Mode = xD writing to !RA, !RB or !RC will affect the input level for each port pin. A 1 will set the level to TTL and a 0 will set it to CMOS.
ST: Mode = xC writing to !RB or !RC will affect the trigger mode of the port pin. A 1 will disable Schmitt-Trigger input and a 0 will enable it.
WKEN: Mode = xB writing to !RB will affect the Wake Up mode for that pin. A 1 will disable multi-input wake up (MIWU). mov m, #$0B
WKED: Mode = xA writing to !RB will affect the Wake Up Edge Selection for that pin. A 1 will select falling edge detection and a 0 will selecte rising edge detection. mov m, #$0A
WKPND: Mode = x9 !RB Multi Input Wake Up Pending Register. mov m, #$09
CMP: Mode = x8 !RB Comparator Enable Register. Bit 7 is the comparator enable bit. A 1 will disable the comparator and a 0 will enable it if port B pins 1 and 2 are configured as inputs. Pin 1 is used as the negative input and pin 2 as the positive input. Bit 0 of the !RB register is the result of the comparison. Bit 6 is the comparator output enable. A 1 will disable output of the comparitor result on port B pin 0 and a 0 will enable it if pin 0 has been configured as an output. Bit 0 of the !RB register is the result of the comparison even if output on pin 0 is not enabled by Bit 6
In the SX48/52 M register indexs the following port control registers.
|MODE Reg.||mov !RA,W||mov !RB,W||mov !RC,W||mov !RD,W||mov !RE,W|
|00h||Read T1CPL||Read T2CPL|
|01h||Read T1CPH||Read T2CPH|
|02h||Read T1R2CML||Read T2R2CML|
|03h||Read T1R2CMH||Read T2R2CMH|
|04h||Read T1R1CML||Read T2R1CML|
|05h||Read T1R1CMH||Read T2R1CMH|
|06h||Read T1CNTB||Read T2CNTB|
|07h||Read T1CNTA||Read T2CNTA|
|0Ch||Read ST_B||Read ST_C||Read ST_D||Read ST_E|
|0Dh||Read LVL_A||Read LVL_B||Read LVL_C||Read LVL_D||Read LVL_E|
|0Eh||Read PLP_A||Read PLP_B||Read PLP_C||Read PLP_D||Read PLP_E|
|0Fh||Read RA Direction||Read RB Direction||Read RC Direction||Read RD Direction||Read RE Direction|
|10h||Clear Timer T1||Clear Timer T2|
|12h||Write T1R2CML||Write T2R2CML|
|13h||Write T1R2CMH||Write T2R2CMH|
|14h||Write T1R1CML||Write T2R1CML|
|15h||Write T1R1CMH||Write T2R1CMH|
|16h||Write T1CNTB||Write T2CNTB|
|17h||Write T1CNTA||Write T2CNTA|
|1Ch||Write ST_B||Write ST_C||Write ST_D||Write ST_E|
|1Dh||Write LVL_A||Write LVL_B||Write LVL_C||Write LVL_D||Write LVL_E|
|1Eh||Write PLP_A||Write PLP_B||Write PLP_C||Write PLP_D||Write PLP_E|
|1Fh||Write RA Direction||Write RB Direction||Write RC Direction||Write RD Direction||Write RE Direction|
Since mov w,#$1F mov m,w will resut in MODE being set to 0Fh in the SX 18/28 and 1Fh in the SX 48/52, and mov m,#$1F will assemble as mov m,#$0F on the SXKey52 v 1.07 to 1.09 it should be used in place of mov m,#$0F in all cases.
The following example shows common code used to configure the ports:
mov W,#$1F ;don't mov m,#$1F, SXKey52 will assemble mov m,#$0F instead mov M,W ;Set up MODE for Data ;Direction configuration mov !RA,#$03 ;RA3, RA2 are Outputs, ;RA1, RA0 are Inputs mov W,#$1E mov M,W ;Set up MODE for Pull-Up ;configuration mov !RA,#$01 ;RA3, RA1 Unaffected, ;Pull-up enabled on RA0 mov W,#$1D mov M,W ;Set up MODE for ;TTL/CMOS configuration mov !RA,#$02 ;RA3,RA2,RA0 unaffected, ;RA1 has CMOS voltage level
The following Macro will setup the ports using a simpler command:
in EQU $F00 out EQU $FFF pull EQU $E00 float EQU $EFF cmos EQU $D00 ttl EQU $DFF porthelp MACRO ERROR 'USAGE: port r[a,b,c,d,e] [in,out,pull,float,cmos,ttl] bits' ENDM port MACRO 3 noexpand IF \1=RA OR \1=RB OR \1=RC OR \1=RD OR \1=RE ELSE porthelp ENDIF IF \2=in OR \2=out OR \2=pull OR \2=float OR \2=cmos OR \2=ttl ELSE porthelp ENDIF expand _PortMode = (\2 / $100) | $10 mov w, #_PortMode mov m,w _Port = \1 _PortMask = (\2//$100)^\3 mov !_Port, #_PortMask noexpand ENDM port ra, out, %10101010
I am trying to implement a MAC instruction for a digital FIR filter. Although, the SX28AC does not have a MAC instruction, can I still implement code to realize it?
Yes, in general you can.... but the exact definition of the MAC instruction will be necessary
Unused Pins. +
weak pullup resister +
Syncronous Input Enable
Input / Output Port Expansion
|file: /Techref/scenix/sxports.htm, 12KB, , updated: 2007/9/20 15:07, local time: 2022/8/13 17:01,
|©2022 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://massmind.org/techref/scenix/sxports.htm"> SX Microcontroler Port Setup</A>
|Did you find what you needed?|
Welcome to massmind.org!
Welcome to massmind.org!