* C runtime library for C52EVB Robot Controller * modified to be Robot Controller with PAULMON2 startup, when reset the board * the C program started to run instead of PAULMON2 monitor * change the startup code file name to c52robot.asm * compiling must invoke -s c52robot.asm ?RAM EQU $F000 External DATA (RAM) Starts here ?RAMEND EQU $FFFF External DATA (RAM) Ends here ORG $8000 CODE Starts here (normally in ROM) LJMP start ORG $800B ORL TH0,#$DC reload timer 0 for 10 ms INC cputick RETI * service timer2 auto reload shift 16-bit PWM pattern to P1.7 and P1.6 every 1/1000 s org $802b PUSH PSW PUSH ACC * PWM1 is for motor 1 shifted through P1.7 clr C MOV A,PWM1 RLC A MOV PWM1,A MOV A,PWM1+1 RLC A MOV PWM1+1,A MOV P1.7,C P1.7 for motor 1 MOV A,PWM1 MOV ACC.0,C MOV PWM1,A * PWM2 is for motor 2 shifted through P1.6 clr C MOV A,PWM2 RLC A MOV PWM2,A MOV A,PWM2+1 RLC A MOV PWM2+1,A MOV P1.6,C P1.6 for motor 2 MOV A,PWM2 MOV ACC.0,C MOV PWM2,A POP ACC POP PSW reti * Fixed memory locations for alternate access to the R0-R7 register bank. * If you are NOT useing BANK 0, these equates must be adjusted. ?R0 EQU 0 Used for "POP" from stack ?R1 EQU ?R0+1 Used to load index indirectly ?R2 EQU ?R0+2 "" "" "" "" ?R3 EQU ?R0+3 Used by some runtime lib functions ?R4 EQU ?R0+4 ?R5 EQU ?R0+5 ?R6 EQU ?R0+6 ?R7 EQU ?R0+7 ORG $8100 * DB $A5,$E5,$E0,$A5 signature bytes( remove * when use PAUL's header) DB 253,255,0,0 id 253 = startup DB 0,0,0,0 prompt code vector DB 0,0,0,0 DB 0,0,0,0 DB 0,0,0,0 DB 0,0,0,0 DB 255,255,255,255 length and checksum (255=unused) DB 'C-52 EVB Robot Controller',0 ORG $8100+64 executable code begins here start MOV SP,#?stk-1 Set up initial stack MOV DPTR,#?heap Point to heap storage CLR A Get end of list flag MOVX [DPTR],A Set heap ending address ORL TMOD,#%00000001 set timer 0 to be counter 16 bit SETB IE.7 set bit EA SETB IE.1 set bit ET0 Enable timer 0 interrupt SETB TCON.4 start timer 0 mov $C9,#$00 T2MOD address is $C9 MOV RCAP2H,#$FC MOV RCAP2L,#$65 mov T2CON,#%01000100 start timer 2 producing 1kHz signal SETB IE.5 enable timer2 interrupt LCALL main Execute main() program LJMP $1954 return to PAULMON2 $SE:1 *#map1 Segment 1, Initialized variables $SE:2 *#map2 Segment 2, Internal "register" variables ORG $0008 Internal ram ALWAYS starts here * to use these variables, declare with "extern register char cputick;", say cputick DS 1 PWM1 DS 2 PWM2 DS 2 time DS 2