home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.hp48
- Path: sparky!uunet!ukma!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!csn!stortek!robertt
- From: robertt@atlantis.stortek.com (Robert Thompson x7747)
- Subject: Motor Controller Code
- Message-ID: <1993Jan28.003400.7415@stortek.com>
- Originator: robertt@termite
- Sender: usenet@stortek.com
- Nntp-Posting-Host: termite.stortek.com
- Organization: Storage Technology
- Distribution: na
- Date: Thu, 28 Jan 1993 00:34:00 GMT
- Lines: 138
-
-
- Here is the code I promised. Set your HP48 to 9600 baud odd parity 7 bits
- and hook it up. The codes you send it are as follows:
-
- O = on
- F = off
- Ctrl-A = speed header (sent before two speed bytes)
-
- Speed bytes are values from 0 to 255 inclusive. The first byte
- specifies the on time and the second byte specifies the off time
-
- so to turn the motor on full speed send this:
-
-
- CHR(1)CHR(255)CHR(0)O
-
- Also included is a S-record format file for eprom programmers. I may be
- interested in programming the prom for you for a minimal charge but that
- depends on demand. Let me know.
-
- I used the Pseudo-Sam assembler to assemble this stuff if anyone is
- interested. You can get it from wuarchive in one of the msdos mirrors.
-
- -Robert
-
- --- CUT HERE ---
-
- ;
- ; mcontrol.asm: A simple motor controller for the HP48 or any other device
- ; capable of transmitting ascii data through a serial link.
- ;
- ;
- .equ gotchar,8 ; bit 8 is character ready
- .equ rxchar,h'7f ; character is at location 7f
- .equ onstate,h'7e ; on state of motor
- .equ onsave,h'7f ; save loc for on time
- .equ offsave,h'7e ; save loc for off time
- ;
- .org h'0000
- ljmp init
- ;
- ; since the serial port is the last interrupt vector, the entire service
- ; routine will start at the vector address (23h)
- .org h'0023 ; serial port service routine
- ;
- serialserv: jb ri,notti
- reti
- notti: clr ea
- push psw
- push acc
- clr ri ; clear interrupt flag
- mov a,sbuf ; get char from buffer
- mov c,p
- cpl c
- anl a,#h'7f ; mask parity
- ; mov p1,a ; send char to port 1
- mov rxchar,a ; save charater
- setb gotchar
- pop acc
- pop psw
- setb ea
- reti
- ;
- ; main program
- ;
- init: mov sp,#h'30 ; initialize the stack pointer
- ;
- ; port configuration
- ;
- mov p1,#h'ff ; configure port 1 outputs
- ;
- ; interrupt section
- ;
- mov ie,#b'00010001 ; enable ext0 and es
- mov ip,#b'00000001 ; int0 has highest priority
- ;
- ; timer configuration section. Timer 1 will be generating the serial clock
- ; signal for 9600 baud 7 bits odd parity
- ;
- mov scon,#b'01010010 ; mode 1, reception enabled
- ; and set xmit ready
- mov tcon,#b'11010011 ; auto reload
- ; int0 falling edge triggered
- mov tmod,#b'00100010 ; timers 1 and 0 auto reload
- ; 8 bit timer mode
- mov th1,#h'fd ; timer 1 reload value 9600BPS
- setb tr1 ; turn on timer
- ;
-
- mainloop: jb gotchar,inchar ; wait for a character
- jnb onstate,mainloop
- mov onsave,r2 ; save r2 and r3
- mov offsave,r3
- setb p0.1
- djnz r2,* ; keep motor on for r2 counts
- clr p0.1
- djnz r3,* ; turn motor off for r3 counts
- mov r2,onsave
- mov r3,offsave
- sjmp mainloop
-
- inchar: mov a,rxchar
- clr gotchar
- cjne a,#'O',noton ; is character an O (on)
- on: setb onstate
- ajmp mainloop
-
- noton: cjne a,#'F',speed ; is chacacter an F (off)
- off: clr onstate
- ajmp mainloop
-
- speed: cjne a,#1,invalid ; is char a speed header (^A)
- jnb gotchar,*
- mov a,rxchar ; get on time
- clr gotchar
- mov r2,a
- jnb gotchar,*
- mov a,rxchar ; get off time
- clr gotchar
- mov r3,a
-
- invalid: ajmp mainloop
-
- .end
- .eof
-
- --- CUT HERE ---
-
- :03000000020041BA
- :1000230020980132C2AFC0D0C0E0C298E599A2D0F7
- :10003300B3547FF57FD208D0E0D0D0D2AF327581F0
- :10004300307590FF75A81175B8017598527588D3EE
- :10005300758922758DFDD28E200815307EFA8A7F30
- :100063008B7ED281DAFEC281DBFEAA7FAB7E80E883
- :10007300E57FC208B44F04D27E015BB44604C27E5E
- :10008300015BB401103008FDE57FC208FA3008FDBA
- :07009300E57FC208FB015BE1
- :00000001FF
-