con clk_mode = 1<<24 | (xdiv-1)<<18 | (xmul-1)<<8 | (((xdivp>>1)+15)&15)<<4 | %1000 sys_clk = xtal / xdiv * xmul / xdivp nco = round(float(sys_clk) / float(baudrate) * 64.0) rx_pin = 63 tx_pin = 62 baudrate = 115_200 xtal = 20_000_000 'physical crystal frequency (Prop2 Eval Board is 20 MHz) xdiv = 20 '1-64 xmul = 80 '1-1024 xdivp = 1 '1,2,4,6,...,30 dat org hubset ##clk_mode 'set/enable crystal oscillator + PLL oscillator waitx ##25_000_000/100 'pause 10 ms (still RCFAST) for PLL to stabilise hubset ##clk_mode | %11 'switch to PLL as sysclock source dirl #tx_pin wrpin #%1_11110_0,#tx_pin wxpin ##nco<<10 | 7,#tx_pin dirh #tx_pin '***************GETTING IT THANKS EVANH************** wrpin #%00_11111_0, #rx_pin 'Asynchronous serial receive wxpin ##nco<<10 | 7, #rx_pin 'set baurdrate and framing dirh #rx_pin '**************************************************** call #getchar jmp #testing 'BEGIN PROGRAM PRESS ANY KEY testing mov dividend, #20 mov divisor, #10 call #division call #putnl loc ptrb, #@msg 'test call #print ' add number,#1 ' call #putnl ' call #dec_to_ascii waitx ##sys_clk '* 15 ' jmp #testing '++++++++++++++++++++++++++++++++++++++ division qdiv dividend,divisor getqx dig1 getqy dig2 mov number ,dig1 call #dec_to_ascii mov number,dig2 call #dec_to_ascii '************************************************* '**************************** putspace mov pa, #" " jmp #putchar ret '------------------ putnl mov pa, #13 call #send_char mov pa, #10 jmp #send_char '**************************** send_char rdpin ax, #tx_pin wc if_nc wypin pa, #tx_pin if_nc ret wcz jmp #send_char print rdbyte pa,ptrb++ wz if_z ret wcz call #send_char jmp #print ' GETTING IT WHOOHOO!!!!!!!!!!!!! '************************************************* getchar testp #rx_pin wz 'byte received? if_z rdpin pb,#rx_pin 'read data from pin if_z shr pb, #32-8 'shift data to bottom of register if_z ret wcz 'restore the carry and zero flags of the 'calling routine jmp #getchar 'wait while no data comming in at the pin '------------------ putchar rqpin inb, #tx_pin wc if_nc wypin pb, #tx_pin if_nc ret wcz jmp #putchar '+++++++++++++++++++++++++++++++++++++++++++++++ ' WARNING: this is untested code, it probably does not work as-is ' it's just an example of the kind of thing you would have to do ' to print a small number as a decimal dec_to_ascii qdiv number, #10 ' divide number by 10 getqy digit2 ' get remainder getqx digit1 ' get number/10; we assume it is < 10, if not we would have to iterate add digit1, #"0" ' convert digit1 to ASCII mov pa, digit1 ' print first digit call #send_char add digit2, #"0" ' same as add digit0, #48 mov pa, digit2 ' print second digit call #send_char ret ax long 1 number long 1 adder long 1 bcdstr long 1 bcdlen long 1 digit1 long 1 digit2 long 1 bcdi long 1 dividend long 1 divisor long 1 quotient long 1 dig1 long 1 dig2 long 1 orgh $400 msg byte "test ",13,0 msg2 byte "successful",10,13,0 carriage byte " ",13,0 msg3 byte "dec_to_ascii =",10,13,0 msg4 byte "itod =",10,13,0 initmsg2 byte " MHz",0