PIC16F84電子遊戯(35)
最終更新日:2001年8月7日
携帯着信ランプ(1ページ)へ (2ページ)へ (3ページ)へ (4ページ)

携帯着信ランプの全ソースリスト公開
;**********************************************************************
;    Filename:	    miracle3.asm                                       *
;    Date:          2001/7/14                                        *
;    File Version:                                                    *
;**********************************************************************

	list      p=16F84             ; list directive to define processor
	#include <p16F84.inc>         ; processor specific variable definitions

	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

;***** VARIABLE DEFINITIONS
w_temp        EQU     0x0C        ; variable used for context saving 
status_temp   EQU     0x0D        ; variable used for context saving

led_data		EQU	0x11		;LED set data
					;led_data,0  RED LED
					;led_data,1  GREEN LED
					;led_data,2  BLUE LED

acount1		EQU	0x13		;LED auto count ram1
acount2		EQU	0x14		;LED auto count ram2 

wait_data		EQU	0x15		;wait data ram

color_count	EQU	0x16		;color count ram
taihi		EQU	0x17		;taihi data

red_count		EQU	0x19		;RED LED count ram
green_count	EQU	0x1a		;GREEN LED count ram
blue_count	EQU	0x1b		;BLUE LED count ram
int_count1	EQU	0x1c		;int count1
int_count2	EQU	0x1d		;int count2

red_on		EQU	0x20		;RED LED ON data ram
red_off		EQU	0x21		;RED LED OFF data ram
green_on		EQU	0x22		;GREEN LED ON data ram
green_off		EQU	0x23		;GREEN LED OFF data ram
blue_on		EQU	0x24		;BLUE LED ON data ram
blue_off		EQU	0x25		;BLUE LED OFF data ram

tm0_setdata	EQU	0f3h		;FFH-F3H=12 12*16=192usec
;**********************************************************************
		ORG     0x000             ; processor reset vector
  		goto    main              ; go to beginning of program


		ORG     0x004             ; interrupt vector location
		movwf   w_temp            ; save off current W register contents
		movf	STATUS,w          ; move status register into W register
		movwf	status_temp       ; save off contents of STATUS register
		;---------------------------------------------------------------
		bcf	INTCON,T0IF
		movlw	tm0_setdata
		movwf	TMR0
		;---------------------------------
		movlw	01h
		addwf	int_count1,1
		btfsc	STATUS,0
		incf	int_count2,1
		;---------------------------------
		movlw	01h		;LED mode auto shori
		addwf	acount1,1
		btfsc	STATUS,0
		incf	acount2,1
		btfss	acount2,3
		goto	red_leds
		call	led_change	
		call	led_set
		call	auto_clear
		;----------------------- RED
red_leds		decfsz	red_count,1
		goto	green_leds
		btfsc	led_data,0	;RED OFF?
		goto	red_leds_2
red_leds_3	bsf	led_data,0	;RED ON
		movf	red_on,0
		movwf	red_count
		movf	red_count,0
		btfsc	STATUS,2
		goto	red_leds_2
		goto	green_leds
red_leds_2	bcf	led_data,0	;RED OFF
		movf	red_off,0
		movwf	red_count
		movf	red_count,0
		btfsc	STATUS,2
		goto	red_leds_3		

		;----------------------- GREEN
green_leds	decfsz	green_count,1
		goto	blue_leds
		btfsc	led_data,1	;GREEN OFF?
		goto	green_leds_2
green_leds_3	bsf	led_data,1	;GREEN ON
		movf	green_on,0
		movwf	green_count
		movf	green_count,0
		btfsc	STATUS,2
		goto	green_leds_2
		goto	blue_leds
green_leds_2	bcf	led_data,1	;GREEN OFF
		movf	green_off,0
		movwf	green_count
		movf	green_count,0
		btfsc	STATUS,2
		goto	green_leds_3

		;---------------------- BLUE
blue_leds		decfsz	blue_count,1
		goto	next_leds
		btfsc	led_data,2	;BLUE OFF?
		goto	blue_leds_2
blue_leds_3	bsf	led_data,2	;BLUE ON
		movf	blue_on,0
		movwf	blue_count
		movf	blue_count,0
		btfsc	STATUS,2
		goto	blue_leds_2
		goto	next_leds
blue_leds_2	bcf	led_data,2	;BLUE OFF
		movf	blue_off,0
		movwf	blue_count
		movf	blue_count,0
		btfsc	STATUS,2
		goto	blue_leds_3
		;----------------------------------
next_leds
		;----------------------------------
int_end
		movf    status_temp,w     ; retrieve copy of STATUS register
		movwf	STATUS            ; restore pre-isr STATUS register contents
		swapf   w_temp,f
		swapf   w_temp,w          ; restore pre-isr W register contents
		retfie                    ; return from interrupt
;--------------------------------------------------------------------------
main
		call	port_set
		movlw	0ffh
		movwf	PORTA
		movlw	0c0h
		movwf	PORTB

		call	timer0_set

		movlw	10h
		movwf	color_count
		call	auto_clear

		movlw	00h
		movwf	led_data	;RED OFF,GREEN OFF,BLUE OFF
		call	set_lo_leds
		movf	red_on,0
		movwf	red_count	;RED count data set
		movf	green_on,0
		movwf	green_count	;GREEN count data set
		movf	blue_on,0
		movwf	blue_count	;BLUE count data set

main_sleep
		bcf	INTCON,GIE
		nop
		bcf	INTCON,T0IE
		nop
		bcf	INTCON,T0IF
		nop
		bcf	INTCON,RBIF
		nop
		bsf	INTCON,RBIE
		nop
		call	icnt_clear
		movlw	0c0h
		movwf	PORTB
		nop
		sleep
		nop
		bcf	INTCON,RBIE
		nop
		call	icnt_clear
		bsf	INTCON,GIE
		nop
		bsf	INTCON,T0IE
		nop
main_loop
;-------------------------------------- led tentou		
		movf	led_data,0
		iorlw	0c0h
		movwf	PORTB
;--------------------------------------

		btfss	int_count2,7
		goto	main_loop
		goto	main_sleep
;-------------------------------------------------------------------------------
wait_1		
		movlw	0ffh
		movwf	wait_data
wait_2
		decfsz	wait_data,1
		goto	wait_2
		return
;-------------------------------------------------------------------------------
auto_clear	movlw	00h
		movwf	acount1		;LED auto count clear
		movwf	acount2
		return
;-------------------------------------------------------------------------------
icnt_clear	movlw	00h
		movwf	int_count1
		movwf	int_count2
		return
;------------------------------------------------------------------------------
led_change	decf	color_count,1
		btfsc	STATUS,2
		goto	led_change2
		return
led_change2	movlw	10h
		movwf	color_count
		return
;-------------------------------------------------------------------------------
led_set		call	set_on_red
		movwf	red_on
		call	set_off_red
		movwf	red_off

		call	set_on_green
		movwf	green_on
		call	set_off_green
		movwf	green_off

		call	set_on_blue
		movwf	blue_on
		call	set_off_blue
		movwf	blue_off
		
		return
;--------------------------------------------------------------------------------
set_on_red	movf	color_count,0
		movwf	taihi
		movlw	low(red_on_table)
		addwf	taihi,1
		movlw	high(red_on_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
red_on_table	retlw	70h
		retlw	20h
		retlw	00h
		retlw	20h
		retlw	00h
		retlw	20h
		retlw	00h
		retlw	20h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	00h
		retlw	70h
		retlw	00h
		retlw	00h
		retlw	70h

set_off_red	movf	color_count,0
		movwf	taihi
		movlw	low(red_off_table)
		addwf	taihi,1
		movlw	high(red_off_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
red_off_table	retlw	00h
		retlw	50h
		retlw	70h
		retlw	50h
		retlw	70h
		retlw	50h
		retlw	70h
		retlw	50h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	70h
		retlw	00h
		retlw	70h
		retlw	70h
		retlw	00h

;--------------------------------------------------------------------------------
set_on_green	movf	color_count,0
		movwf	taihi
		movlw	low(green_on_table)
		addwf	taihi,1
		movlw	high(green_on_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
green_on_table	retlw	70h
		retlw	00h
		retlw	20h
		retlw	20h
		retlw	20h
		retlw	00h
		retlw	70h
		retlw	70h
		retlw	00h
		retlw	20h
		retlw	70h
		retlw	00h
		retlw	70h
		retlw	70h
		retlw	00h
		retlw	70h
		retlw	00h

set_off_green	movf	color_count,0
		movwf	taihi
		movlw	low(green_off_table)
		addwf	taihi,1
		movlw	high(green_off_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
green_off_table	retlw	00h
		retlw	70h
		retlw	50h
		retlw	50h
		retlw	50h
		retlw	70h
		retlw	00h
		retlw	00h
		retlw	70h
		retlw	50h
		retlw	00h
		retlw	70h
		retlw	00h
		retlw	00h
		retlw	70h
		retlw	00h
		retlw	70h

;--------------------------------------------------------------------------------
set_on_blue	movf	color_count,0
		movwf	taihi
		movlw	low(blue_on_table)
		addwf	taihi,1
		movlw	high(blue_on_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
blue_on_table	retlw	70h
		retlw	20h
		retlw	20h
		retlw	00h
		retlw	70h
		retlw	70h
		retlw	20h
		retlw	00h
		retlw	20h
		retlw	00h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	00h
		retlw	70h
		retlw	00h
		retlw	00h

set_off_blue	movf	color_count,0
		movwf	taihi
		movlw	low(blue_off_table)
		addwf	taihi,1
		movlw	high(blue_off_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
blue_off_table	retlw	00h
		retlw	50h
		retlw	50h
		retlw	70h
		retlw	00h
		retlw	00h
		retlw	50h
		retlw	70h
		retlw	50h
		retlw	70h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	70h
		retlw	00h
		retlw	70h
		retlw	70h
;-------------------------------------------------------------------------------
set_lo_leds	movlw	00h
		movwf	red_on
		movwf	green_on
		movwf	blue_on

		movlw	70h
		movwf	red_off
		movwf	green_off
		movwf	blue_off
		return
;-------------------------------------------------------------------------------
port_set				;RA0,RA1,RA2,RA3,RA4(OUT)				
					;RB0,RB1,RB2,RB3,RB4,RB5(OUT)
					;RB6,RB7(IN)
		bsf	STATUS,RP0
		clrf	TRISA
		clrf	TRISB
		bsf	TRISB,7
		nop
		bsf	TRISB,6
		nop
		bcf	STATUS,RP0
		return

timer0_set

		bsf	STATUS,RP0
		movlw	083h		;(1)PORTB NOT PULLUP
					;(0)INTEDG
					;(0)TOCS
					;(0)TOSE
					;(0)PSA
					;(011)1/16
		movwf	OPTION_REG
		bcf	STATUS,RP0
		
		movlw	tm0_setdata
		movwf	TMR0
		return


		END                     ; directive 'end of program'
携帯着信ランプの全HEXコード
HEXコードです。メモ帳などのテキストエディタにコピー&ペーストしてファイルすればPICに書き込めるデータに出来ます。
:020000004F2887
:080008008C0003088D000B11B0
:10001000F330810001309C0703189D0A01309307DB
:100020000318940A941D17288B2092208320990B83
:1000300028281118222811142008990019080319DA
:1000400022282828111021089900190803191B28B3
:100050009A0B392891183328911422089A001A080B
:10006000031933283928911023089A001A08031914
:100070002C289B0B4A2811194428111524089B0091
:100080001B08031944284A28111125089B001B0846
:1000900003193D280D0883008C0E0C0E09004A211F
:1000A000FF308500C0308600532110309600832039
:1000B0000030910041212008990022089A0024086C
:1000C0009B008B1300008B1200000B1100000B1023
:1000D00000008B1500008720C03086000000630000
:1000E00000008B11000087208B1700008B1600008A
:1000F0001108C03886009D1F78286128FF309500C0
:10010000950B802808000030930094000800003010
:100110009C009D000800960303198F2808001030EA
:10012000960008009F20A000BA20A100D520A200C0
:10013000F020A3000B21A4002621A500080016082A
:100140009700A930970700308A0003188A0A170819
:1001500082007034203400342034003420340034E1
:10016000203470347034703470340034703400349F
:100170000034703416089700C430970700308A00A6
:1001800003188A0A1708820000345034703450343F
:10019000703450347034503400340034003400343F
:1001A0007034003470347034003416089700DF3037
:1001B000970700308A0003188A0A170882007034F3
:1001C000003420342034203400347034703400344F
:1001D000203470340034703470340034703400349F
:1001E00016089700FA30970700308A0003188A0A29
:1001F0001708820000347034503450345034703456
:10020000003400347034503400347034003400341E
:100210007034003470341608970015309707013099
:100220008A0003188A0A17088200703420342034A8
:10023000003470347034203400342034003470348E
:100240007034703400347034003400341608970071
:100250003030970701308A0003188A0A1708820095
:10026000003450345034703400340034503470341E
:10027000503470340034003400347034003470343E
:1002800070340030A000A200A4007030A100A300D0
:10029000A500080083168501860186170000061751
:1002A0000000831208008316833081008312F3302C
:0402B00081000800C1
:02400E00F13F80
:00000001FF
(miracle3.hex)
携帯着信ランプの完成
着信ランプが色を変えながら点滅する姿を見て下さい。
(デジタルカメラで撮ったので的を得ていない色もあります。すいません。本当は16色で点滅します。)
先端のオブジェを色々換えてみると大変楽しいですよ。
とういことで、携帯着信ランプ大完成です。
いかがでしたか。結構実用的な製作でしたね。皆さんで光り方は色々研究して下さい。
これからも益々面白くなる「PIC16F84電子遊戯」をよろしくお願いいたします。

不明点などあればメールお願いいたします。nonchansoft@nifty.com

Copyright(c)2000-2001 nonchansoft