;lp.asm - Laser Projector Control Software ; ;Version 0.01 - 2007-10-23 ; ;Copyright (c) 2007 Joseph Battaglia ; ;Permission is hereby granted, free of charge, to any person obtaining a copy ;of this software and associated documentation files (the "Software"), to ;deal in the Software without restriction, including without limitation the ;rights to use, copy, modify, merge, publish, distribute, sublicense, and/or ;sell copies of the Software, and to permit persons to whom the Software is ;furnished to do so, subject to the following conditions: ; ;The above copyright notice and this permission notice shall be included in ;all copies or substantial portions of the Software. ; ;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ;FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS ;IN THE SOFTWARE. ;Include the register/bit definitions for the ATtiny2313 .nolist .include "tn2313def.inc" ;Definition file supplied by Atmel .list ;Register assignments .def rmp = r16 ;Multi-purpose register .def rln = r17 ;Scanline register .def rsm = r18 ;Stepper motor offset count register .def rch = r19 ;Character register .def rby = r20 ;Display byte register .def rlr = r21 ;Line reset register ;Labels .equ smo = 0x03 ;Stepper motor offset .equ dly = 0x09 ;Dot delay .equ m1l = 0x0A ;Mode 1 line reset .equ m2l = 0x11 ;Mode 2 line reset ;Code segment .cseg ;Reset and Interrupt Vectors .org 0x000 rjmp reset ;Reset Handler rjmp sint ;External Interrupt0 Handler rjmp chmode ;External Interrupt1 Handler reti ;Timer1 Capture Handler reti ;Timer1 CaptureA Handler reti ;Timer1 Overflow Handler reti ;Timer0 Overflow Handler reti ;USART0 RX Complete Handler reti ;USART0,UDR Empty Handler reti ;USART0 TX Complete Handler reti ;Analog Compare Handler reti ;Pin Change Interrupt reti ;Timer1 Compare B Handler reti ;Timer0 Compare A Handler reti ;Timer0 Compare B Handler reti ;USI Start Handler reti ;USI Overflow Handler reti ;EEPROM Ready Handler reti ;Watchdog Overflow Handler ;Change the display mode (single line / dual line) by toggling rlr between m1l ;and m2l. chmode: cpi rlr,m2l brne chmode_l1 ldi rlr,m1l reti chmode_l1: ldi rlr,m2l reti ;Reset procedure reset: ;Set the stack pointer to the top of RAM ldi rmp,low(RAMEND) out SPL,rmp ;Enable interrupts sei ;Set INT0 and INT1 to trigger on the rising edge in rmp,MCUCR ori rmp,0x0F out MCUCR,rmp ;Enable INT0 and INT1 in rmp,GIMSK ori rmp,0xC0 out GIMSK,rmp ;Set the data direction registers for ports B and D: ;Port B - bits 0-7 as output ;Port D - bit 0 as output, bits 1-7 as input ldi rmp,0xFF out DDRB,rmp ldi rmp,0x01 out DDRD,rmp ;Clear the scanline register clr rln ;Set the stepper motor offset count ldi rsm,smo ;Set the line reset register to mode 1 ldi rlr,m1l ;Main loop ;The remainder of the program is interrupt-driven mainloop: rjmp mainloop ;Stepper motor interrupt procedure sint: ;Take the stepper motor offset into account by returning ;if the counter hasn't been reached dec rsm brne sint_l6 ldi rsm,smo ;Mode 2 delay cpi rln,m2l-1 brne sint_l1 dec rln out PORTB,rln reti sint_l1: ;Mode 1 delay cpi rlr,m1l brne sint_l2 sbrs rln,3 rjmp sint_l2 dec rln mov rmp,rln inc rmp inc rmp out PORTB,rmp reti sint_l2: ;Determine which line of text to display (if operating in ;mode 2) cpi rln,0x08 brlt sint_l3 ;Load the message for line 2 ldi ZL,low(l2msg<<1) ldi ZH,high(l2msg<<1) rjmp sint_l4 sint_l3: ;Load the message for line 1 ldi ZL,low(l1msg<<1) ldi ZH,high(l1msg<<1) sint_l4: ;Load the next character into rch or break if we're done lpm rch,Z+ cpi rch,0xFF breq sint_l5 ;Load the line definition for the character, print it, and ;loop to the next rcall ldascii rcall pbyte rjmp sint_l4 sint_l5: ;Decrement the line rcall decln sint_l6: reti ;Load the ASCII definition for the character in rch and line in rln ldascii: ;Save Z push ZL push ZH ;Load the ASCII table ldi ZL,low(atbl<<1) ldi ZH,high(atbl<<1) ;Add the character offset to the ASCII pointer clr rmp lsl rch rol rmp lsl rch rol rmp lsl rch rol rmp add ZL,rch adc ZH,rmp ;Add the Z pointer to the current line definition, accounting ;for mode 2 operation adiw ZH:ZL,0x07 push rln ldi rmp,0x08 cp rln,rmp brlt ldascii_l1 sub rln,rmp ldascii_l1: sub ZL,rln sbci ZH,0x00 pop rln ;Set rby to the current character line definition lpm rby,Z ;Restore Z pop ZH pop ZL ret ;Decrement the line decln: ;Compare the current line with 0x00, resetting it if it's equal cpi rln,0x00 brne decln_l1 ;Reset the line to rlr mov rln,rlr decln_l1: ;Decrement the line dec rln ;Move rln to a more linear range if operating in mode 1 mov rmp,rln cpi rlr,m1l brne decln_l2 inc rmp decln_l2: ;Set PORTB to the current line out PORTB,rmp ret ;Print the byte rby pbyte: ldi rmp,0x08 pbyte_l1: ;Print a blank or dot, depending on the state of bit 0 sbrs rby,0 rcall pblank sbrc rby,0 rcall pdot ;Logical shift rby right, decrement the counter, and loop ;if bits remain to be printed lsr rby dec rmp brne pbyte_l1 ret ;Print a dot pdot: ;Save rmp push rmp ;Turn PD0 on and delay ldi rmp,dly sbi PORTD,0 pdot_l1: dec rmp brne pdot_l1 ;Turn PD0 off cbi PORTD,0 ;Restore rmp pop rmp ret ;Don't print a dot, but use the same number of CPU cycles as if we were to pblank: ;Save rmp push rmp ;Turn PD0 on and delay ldi rmp,dly cbi PORTD,0 pblank_l1: dec rmp brne pblank_l1 ;Turn PD0 off cbi PORTD,0 ;Restore rmp pop rmp ret atbl: .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 0 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 1 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 2 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 3 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 4 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 5 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 6 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 7 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 8 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 9 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 10 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 11 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 12 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 13 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 14 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 15 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 16 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 17 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 18 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 19 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 20 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 21 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 22 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 23 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 24 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 25 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 26 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 27 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 28 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 29 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 30 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 31 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 32 .db 0x00,0x18,0x00,0x18,0x18,0x18,0x18,0x18 ;ASCII 33 .db 0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66 ;ASCII 34 .db 0x00,0x6C,0xFE,0x6C,0x6C,0xFE,0x6C,0x00 ;ASCII 35 .db 0x00,0x18,0x7C,0x06,0x3C,0x60,0x3E,0x18 ;ASCII 36 .db 0x00,0x46,0x66,0x30,0x18,0x6C,0x66,0x00 ;ASCII 37 .db 0x00,0x76,0xCC,0xDE,0x70,0x38,0x6C,0x38 ;ASCII 38 .db 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x18 ;ASCII 39 .db 0x00,0x0E,0x1C,0x18,0x18,0x18,0x1C,0x0E ;ASCII 40 .db 0x00,0x70,0x38,0x18,0x18,0x18,0x38,0x70 ;ASCII 41 .db 0x00,0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00 ;ASCII 42 .db 0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00 ;ASCII 43 .db 0x60,0x30,0x30,0x00,0x00,0x00,0x00,0x00 ;ASCII 44 .db 0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00 ;ASCII 45 .db 0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00 ;ASCII 46 .db 0x00,0x40,0x60,0x30,0x18,0x0C,0x06,0x02 ;ASCII 47 .db 0x00,0x3C,0x66,0x66,0x76,0x6E,0x66,0x3C ;ASCII 48 .db 0x00,0x7E,0x18,0x18,0x18,0x18,0x38,0x18 ;ASCII 49 .db 0x00,0x7E,0x30,0x18,0x0C,0x06,0x66,0x3C ;ASCII 50 .db 0x00,0x3C,0x66,0x06,0x0C,0x18,0x0C,0x7E ;ASCII 51 .db 0x00,0x0C,0x0C,0x7E,0x6C,0x3C,0x1C,0x0C ;ASCII 52 .db 0x00,0x3C,0x66,0x06,0x06,0x7C,0x60,0x7E ;ASCII 53 .db 0x00,0x3C,0x66,0x66,0x7C,0x60,0x60,0x3C ;ASCII 54 .db 0x00,0x30,0x30,0x30,0x18,0x0C,0x06,0x7E ;ASCII 55 .db 0x00,0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C ;ASCII 56 .db 0x00,0x38,0x0C,0x06,0x3E,0x66,0x66,0x3C ;ASCII 57 .db 0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x00 ;ASCII 58 .db 0x00,0x30,0x18,0x18,0x00,0x18,0x18,0x00 ;ASCII 59 .db 0x00,0x06,0x0C,0x18,0x30,0x18,0x0C,0x06 ;ASCII 60 .db 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00 ;ASCII 61 .db 0x00,0x60,0x30,0x18,0x0C,0x18,0x30,0x60 ;ASCII 62 .db 0x00,0x18,0x00,0x18,0x0C,0x06,0x66,0x3C ;ASCII 63 .db 0x00,0x3E,0x60,0x6E,0x6A,0x6E,0x66,0x3C ;ASCII 64 .db 0x00,0x66,0x66,0x7E,0x66,0x66,0x3C,0x18 ;ASCII 65 .db 0x00,0x7C,0x66,0x66,0x7C,0x66,0x66,0x7C ;ASCII 66 .db 0x00,0x3C,0x66,0x60,0x60,0x60,0x66,0x3C ;ASCII 67 .db 0x00,0x78,0x6C,0x66,0x66,0x66,0x6C,0x78 ;ASCII 68 .db 0x00,0x7E,0x60,0x60,0x7C,0x60,0x60,0x7E ;ASCII 69 .db 0x00,0x60,0x60,0x60,0x7C,0x60,0x60,0x7E ;ASCII 70 .db 0x00,0x3E,0x66,0x66,0x6E,0x60,0x60,0x3E ;ASCII 71 .db 0x00,0x66,0x66,0x66,0x7E,0x66,0x66,0x66 ;ASCII 72 .db 0x00,0x3C,0x18,0x18,0x18,0x18,0x18,0x3C ;ASCII 73 .db 0x00,0x3C,0x66,0x06,0x06,0x06,0x06,0x06 ;ASCII 74 .db 0x00,0x66,0x6C,0x78,0x70,0x78,0x6C,0x66 ;ASCII 75 .db 0x00,0x7E,0x60,0x60,0x60,0x60,0x60,0x60 ;ASCII 76 .db 0x00,0xC6,0xC6,0xC6,0xD6,0xFE,0xEE,0xC6 ;ASCII 77 .db 0x00,0x66,0x66,0x6E,0x7E,0x7E,0x76,0x66 ;ASCII 78 .db 0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x3C ;ASCII 79 .db 0x00,0x60,0x60,0x60,0x7C,0x66,0x66,0x7C ;ASCII 80 .db 0x00,0x36,0x6C,0x76,0x66,0x66,0x66,0x3C ;ASCII 81 .db 0x00,0x66,0x66,0x6C,0x7C,0x66,0x66,0x7C ;ASCII 82 .db 0x00,0x3C,0x66,0x06,0x3C,0x60,0x66,0x3C ;ASCII 83 .db 0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x7E ;ASCII 84 .db 0x00,0x3E,0x66,0x66,0x66,0x66,0x66,0x66 ;ASCII 85 .db 0x00,0x18,0x3C,0x66,0x66,0x66,0x66,0x66 ;ASCII 86 .db 0x00,0xC6,0xEE,0xFE,0xD6,0xC6,0xC6,0xC6 ;ASCII 87 .db 0x00,0x66,0x66,0x3C,0x18,0x3C,0x66,0x66 ;ASCII 88 .db 0x00,0x18,0x18,0x18,0x3C,0x66,0x66,0x66 ;ASCII 89 .db 0x00,0x7E,0x60,0x30,0x18,0x0C,0x06,0x7E ;ASCII 90 .db 0x00,0x1E,0x18,0x18,0x18,0x18,0x18,0x1E ;ASCII 91 .db 0x00,0x02,0x06,0x0C,0x18,0x30,0x60,0x40 ;ASCII 92 .db 0x00,0x78,0x18,0x18,0x18,0x18,0x18,0x78 ;ASCII 93 .db 0x00,0x00,0x00,0x00,0xC6,0x6C,0x38,0x10 ;ASCII 94 .db 0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00 ;ASCII 95 .db 0x00,0x00,0x00,0x00,0x30,0x60,0xC0,0x00 ;ASCII 96 .db 0x00,0x3E,0x66,0x3E,0x06,0x3C,0x00,0x00 ;ASCII 97 .db 0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60 ;ASCII 98 .db 0x00,0x3C,0x60,0x60,0x60,0x3C,0x00,0x00 ;ASCII 99 .db 0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x06 ;ASCII 100 .db 0x00,0x3C,0x60,0x7E,0x66,0x3C,0x00,0x00 ;ASCII 101 .db 0x00,0x30,0x30,0x30,0x30,0x7C,0x30,0x1C ;ASCII 102 .db 0x7C,0x06,0x3E,0x66,0x66,0x3E,0x00,0x00 ;ASCII 103 .db 0x00,0x66,0x66,0x66,0x66,0x7C,0x60,0x60 ;ASCII 104 .db 0x00,0x3C,0x18,0x18,0x18,0x38,0x00,0x18 ;ASCII 105 .db 0x70,0x18,0x18,0x18,0x18,0x18,0x00,0x18 ;ASCII 106 .db 0x00,0x66,0x6C,0x78,0x6C,0x66,0x60,0x60 ;ASCII 107 .db 0x00,0x3C,0x18,0x18,0x18,0x18,0x18,0x38 ;ASCII 108 .db 0x00,0xC6,0xC6,0xD6,0xFE,0xEC,0x00,0x00 ;ASCII 109 .db 0x00,0x66,0x66,0x66,0x66,0x7C,0x00,0x00 ;ASCII 110 .db 0x00,0x3C,0x66,0x66,0x66,0x3C,0x00,0x00 ;ASCII 111 .db 0x60,0x7C,0x66,0x66,0x66,0x7C,0x00,0x00 ;ASCII 112 .db 0x06,0x3E,0x66,0x66,0x66,0x3E,0x00,0x00 ;ASCII 113 .db 0x00,0x60,0x60,0x60,0x66,0x7C,0x00,0x00 ;ASCII 114 .db 0x00,0x7C,0x06,0x3C,0x60,0x3E,0x00,0x00 ;ASCII 115 .db 0x00,0x0E,0x18,0x18,0x18,0x7E,0x18,0x00 ;ASCII 116 .db 0x00,0x3E,0x66,0x66,0x66,0x66,0x00,0x00 ;ASCII 117 .db 0x00,0x18,0x3C,0x66,0x66,0x66,0x00,0x00 ;ASCII 118 .db 0x00,0x6C,0x7C,0xD6,0xC6,0xC6,0x00,0x00 ;ASCII 119 .db 0x00,0x66,0x3C,0x18,0x3C,0x66,0x00,0x00 ;ASCII 120 .db 0x7C,0x06,0x3E,0x66,0x66,0x66,0x00,0x00 ;ASCII 121 .db 0x00,0x7E,0x30,0x18,0x0C,0x7E,0x00,0x00 ;ASCII 122 .db 0x00,0x0E,0x18,0x18,0x30,0x18,0x18,0x0E ;ASCII 123 .db 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18 ;ASCII 124 .db 0x00,0x70,0x18,0x18,0x0C,0x18,0x18,0x70 ;ASCII 125 .db 0x00,0x00,0x00,0x0C,0x9E,0xF2,0x60,0x00 ;ASCII 126 .db 0x00,0x7E,0x62,0x34,0x34,0x18,0x18,0x00 ;ASCII 127 l1msg: .db " ten.liahpes.www//:ptth - rotcejorP VOP resaL" .db 0xFF l2msg: .db " !troppus enil owt htiW" .db 0xFF