;lcd kunio.h (CPU:8MHz) ;**** includes **** .include "m88pdef.inc" ; Load immediate word into the resister pair. ; ldiw Z(X,Y),var .macro ldiw ldi @0L,low(@1) ldi @0H,high(@1) .endm ; Output immediate outi port,var .macro outi ldi r16,@1 out @0,r16 .endm .MACRO cpi16 ;cpi16 ra,rb,0xHHHH ;ra:rb-0xHHHH set flags:N,C,Z push @0 push @1 subi @1,low(@2) sbci @0,high(@2) pop @1 pop @0 .ENDMACRO .macro stsi ldi r16,@1 sts @0,r16 .endm .MACRO addi16 ;addi16 ra,rb,0xHHHH subi @1,low(-@2) sbci @0,high(-@2) .ENDMACRO ;***************************** ;* レジスタ変数 設定 * ;***************************** .def mem_l = r10 .def mem_h = r11 .def mem_p0 = r12 .def temp1 = r16 .def temp2 = r17 .def temp3 = r18 .def temp4 = r19 ;***************************** ;*  ビット 設定  * ;** PORTB *** .equ lcd_cs= 0 .equ lcd_rs= 1 ;.equ = 2 ;SS ;.equ = 3 ;MOSI lcd_SDI ;.equ = 4 ;MISO ;.equ = 5 ;SCK lcd_SCLK ;.equ = 6 ;.equ = 7 ;** PORTD ** ;.equ = 0 ;.equ = 1 ;.equ = 2 ;.equ = 3 ;.equ = 4 ;.equ = 5 ;.equ = 6 ;.equ = 7 ;** PORTC *** ;.equ = 0 ;.equ = 1 ;.equ = 2 ;.equ = 3 .equ sda= 4 .equ scl= 5 ;.equ = 6 .dseg dram: .byte 60 kp_dat: .byte 18 m_dat: .byte 20 .cseg ;********************* ;* 割込みベクター * ;********************* rjmp start ;各種リセット reti ;RJMP EXT_INT0 ;外部割り込み要求0 reti ;EXT_INT1 ;外部割り込み要求1 reti ;TIM2_COMP ;タイマ/カウンタ2 比較一致 reti ;TIM2_OVF ;タイマ/カウンタ2 オーバーフロー reti ;TIM1_CAPT ;タイマ/カウンタ1 キャプチャ発生 mp3_dreq L→H sleep mood end reti ;TIM1_COMPA ;タイマ/カウンタ1 比較A 一致 reti ;TIM1_COMPB ;タイマ/カウンタ1 比較B 一致 reti ;TIM1_OVF ;タイマ/カウンタ1 オーバーフロー reti ;TIM0_OVF ;タイマ/カウンタ0 オーバーフロー reti ;SPI_STC ;SPI 転送完了 reti ;USART_RXC ;USART 受信完了 reti ;USART_DRE ;USART 送信バッファ空 reti ;USART_TXC ;USART 送信完了 reti ;ADC_E ;ADC 変換完了 reti ;EE_RDY ;EEPROM 操作可 reti ; ANA_COMP ;アナログ コンパレータ出力遷移 reti ;TWSI ;2 線式シリアル インターフェース状態変化 reti ;SPM_RDY ;SPM 命令操作可 ;********************* ;* メイン プログラム * ;********************* start: ldi temp1,low(RAMEND) out SPL,temp1 ldi temp1,high(RAMEND) out SPH,temp1 ;init Stack Pointer ldi r16,0x80 ;set cpu clk 8MHz sts CLKPR,r16 ldi r16,0x00 ;1 sts CLKPR,r16 ldi temp1,0b11010101 out PORTB,temp1 ldi temp1,0b00101011 out DDRB,temp1 ldi temp1,0b11111111 out PORTC,temp1 ldi temp1,0b00110000 out DDRC,temp1 ldi temp1,0b11111100 out PORTD,temp1 ldi temp1,0b00000010 out DDRD,temp1 USATR_int: stsi UBRR0H,0 stsi UBRR0L,51 ;8MHz/[(51+1)x16]-->9600Hz stsi UCSR0A,1<19200Hz stsi UCSR0B,(1<> NACK send r_d2: ldi temp1,2 rcall wait_us sbi PORTC,scl ldi temp1,3 rcall wait_us ret mem_r0: ldi r20,2-1 rjmp mem_r1 mem_r: ldi r20,18-1 mem_r1: clr r21 ldiw z,kp_dat rcall mem_w mov temp3,mem_h rcall send_dat mov temp3,mem_l rcall send_dat_re rcall start_c ;re_start ldi temp3,0b10100001 ;SLA_R or temp3,mem_p0 rcall send_dat mem_r2: rcall read_dat st z+,temp3 dec r20 brne mem_r2 rcall read_last_dat ;last data read,NACK send st z+,temp3 rcall stop_c ret mem_w: rcall start_c ldi temp3,0b10100000 ;SLA_W or temp3,mem_p0 rcall send_dat ret ;********************************************** lcd_int: cbi PORTB,lcd_cs cbi PORTB,lcd_rs ldi temp1,0xae ;display off rcall spi_out ldi temp1,0xAE //Display = OFF rcall spi_out ldi temp1,0xA0 //ADC = normal rcall spi_out ldi temp1,0xC8 //Common output = revers rcall spi_out ldi temp1,0xA3 //bias = 1/7 rcall spi_out //--内部レギュレータを順番にONする--// ldi temp1,0x2C //power control 1 rcall spi_out ldi temp1,2 rcall wait_ms ldi temp1,0x2E //power control 2 rcall spi_out ldi temp1,2 rcall wait_ms ldi temp1,0x2F //power control 3 rcall spi_out //--コントラスト設定--// ldi temp1,0x23 //Vo voltage resistor ratio set rcall spi_out ldi temp1,0x81 //Electronic volume mode set rcall spi_out ldi temp1,0x1C //Electronic volume value set rcall spi_out //--表示設定--// ldi temp1,0xA4 //display all point = normal(全点灯しない) rcall spi_out ldi temp1,0x40 //display start line = 0 rcall spi_out ldi temp1,0xA6 //Display normal/revers = normal(白黒反転しない) rcall spi_out ldi temp1,0xAF //Display = ON rcall spi_out //Display clear ldi temp2,0xb7//page address 7 dc0: mov temp1,temp2 cbi PORTB,lcd_rs rcall spi_out ldi temp1,0x10 //column address 0 rcall spi_out ldi temp1,0x00 //column address 0 rcall spi_out ldi temp3,128 sbi PORTB,lcd_rs clr temp1 dc1: rcall spi_out dec temp3 brne dc1 dec temp2 cpi temp2,0xb0 brpl dc0 sbi PORTB,lcd_cs ret ;********************************************** ;lcd_com: ; cbi PORTB,lcd_rs ; rjmp lcd_dsp1 ;lcd_dsp: ; sbi PORTB,lcd_rs ;lcd_dsp1: ; cbi PORTB,lcd_cs ; rcall spi_out ; sbi PORTB,lcd_cs ; ret ;********************************************** ;SPI DATA output data=temp1 spi_out: out SPDR,temp1 spi_out1: in r15,SPSR sbrs r15,SPIF rjmp spi_out1 ret ;********************************************* Tx: LDS r0,UCSR0A SBRS r0,UDRE0 ;送信バッファ空きでスキップ RJMP Tx ;送信バッファ空き待機 STS UDR0,R16 ;データ送信(送信開始) RET ;呼び出し元へ復帰 Rx: LDS r0,UCSR0A SBRS r0,RXC0 ;受信完了でスキップ RJMP Rx ;受信完了待機 LDS R16,UDR0 ;受信データ取得 RET ;呼び出し元へ復帰 ;********************************************** wait_us: ;base 8MHz temp1 us (4clocks) nop ; 1clocks dec temp1 ; 1clocks brne wait_us ; 2clocks ret ; wait_ms: ;temp1 ms ldi temp2,100 ;80*100=8000clocks wait_ms_01: ldi temp3,19 ;1clocks 4*(19+1)=80 wait_ms_02: nop ; 1clocks dec temp3 ; 1clocks brne wait_ms_02 ; 2clocks dec temp2 ; 1clocks brne wait_ms_01 ; 2clocks dec temp1 ; 1clocks brne wait_ms ; 2clocks ret ;*********************************************