ST7 quick big-banging assembly hack sought

Hi there I'm commissioning an ST7 board and want to get some bit-banging serial output on one of the port pins. No, I can't use any of the timers. This is a quick test really, I haven't programmed the ST7 in assembler before and I'm not familiar with the instruction set ... which looks like a cross between the 6800 and the 8051??

Anyway ... I have as an example below this bit-banging Transmit routine by Dave Dunfield (wow ... that name rings bells from *many* years ago): This is for the 8051. I want to write something similar for the ST7, writing out to (say) port pin PB5. Can anyone give me some pointers to assembly code which would do this? The 8051 has some useful instructions, and a deterministic cycle time, which I've not yet worked out how to translate to the ST7.

Oh, the baud rate doesn't really matter ;-)

Thanks J^n

  • "Bit-bang" serial I/O functions for the 8051.
*
  • These routines transmit and receive serial data using two general
  • I/O pins, in 8 bit, No parity, 1 stop bit format. They are useful
  • for performing serial I/O on 8051 derivatives not having an
  • internal UART, or for implementing a second serial channel.
*
  • Dave Dunfield - May 17, 1994
*
  • NOTE that R0 and R1 are used by the functions. You may wish to
  • add PUSH/POP instructions to save/restore these registers.
  • TXD EQU P1.0 Transmit on this pin RXD EQU P1.1 Receive on this pin
  • The serial baud rate is determined by the processor crystal, and
  • this constant which is calculated as: (((crystal/baud)/12) - 5) / 2 BITTIM EQU 45 ; (((1000000/9600)/12) - 5) / 2
*
  • Transmit character in A via TXD line
  • putc CLR TXD Drop line for start bit MOV R0,#BITTIM Wait full bit-time DJNZ R0,* For START bit MOV R1,#8 Send 8 bits putc1 RRC A Move next bit into carry MOV TXD,C Write next bit MOV R0,#BITTIM Wait full bit-time DJNZ R0,* For DATA bit DJNZ R1,putc1 write 8 bits SETB TXD Set line high RRC A Restore ACC contents MOV R0,#BITTIM Wait full bit-time DJNZ R0,* For STOP bit RET
Reply to
nic
Loading thread data ...

The ST7 is more of a cross between 6805 and 6808. I believe that

6805 code will execute on it binary compatible. (May be one or two instructions that will not)

w..

nic wrote:

Reply to
Walter Banks

Hey, that's *the* Walter Banks! I know your name from ... a long time ago, sir (doffs hat).

OK, that makes more sense. I never used the 6805 which is why it didn't come to mind ... my experience begins with the 6800 & 6502 ... then z80, 6809, 68k, 80x86 ... PIC ... 6809 again ... and then this blighter.

FWIW here's the routine I ended up with. It runs 'mostly OK' on a 1MHz ST7 at 9600 baud. It would be more accurate at 2400baud; for my current purposes this is adequate.

Regards Jon N

; enter with char in A

deltime: set 14 ; gives around 9600 baud with 1MHz clock rate

ld y,#$08 ; cy3 - y reg contains the nb+1 of bit to be transmited.

bres _PBDR, #5 ; cy5 - drop line for start bit

; DELAY ld x, #deltime ; cy3 $N: dec x ; cy3 jrne $L ; cy3

APP_bb_txbyte_1: rrc a ; cy3 - transfer next bit from a in the carry and load receive one. jrc APP_bb_txbyte_2 ; cy3 - transmit data bit from carry flag to the i/o port. bres _PBDR, #5 ; cy5 jrt APP_bb_txbyte_3 ; cy3

APP_bb_txbyte_2: bset _PBDR, #5 ; cy5

APP_bb_txbyte_3:

; DELAY ld x, #deltime ; cy3 $N: dec x ; cy3 jrne $L ; cy3

dec y ; cy4 - one more bit transmited. jrne APP_bb_txbyte_1 ; cy3 - data byte is not yet all transmit => next bit.

bset _PBDR, #5 ; cy5 - Stop bit

; DELAY ld x, #deltime ; cy3 $N: dec x ; cy3 jrne $L ; cy3

ret ; cy6

Reply to
nic

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.