卒 業 研 究 報 告

Similar documents
3 4 PIC

,, ( ) 5 ma ( ) 5V V 5 6 A B C D E F G H I J , LED LED, LED, 7 LED,, 7 LED ( ) V LED VCC 5V 7 LED VCC f g f a g b a b c e d e d c dp dp VCC (

untitled

untitled

前付(念).indd

PIC18 Istructios PIC16, PIC x Microchip Techology Icorporated. All Rights Reserved. PICmicro PIC18 52

スライド 1

Microsoft PowerPoint - 工学ゼミⅢLED1回_2018

3 1EEPROMElectrically Erasable PROM PROMProgrammable ROM 2 EEPROM 3

スライド 1

Taro11-…e…L…X…g.jtd

回路 : Vdd GND 回路図と呼べるようなものではありません オシレータは外部 ( セラミック発振子 ) なので GP4 と GP5 は使えません 四角の枠内はモジュールなので ここから VDD GND TX RX の4 本をつなぐだけです 測定端子 (GP0) は 1MΩの抵抗と 2MΩの半固

DVIOUT-soturon

スライド 1

PIC (, 2, 3 ) PIC ( 1, 2, 3 ) 1 2 (, 2 ) PIC ( 1, 2 ) 2.1 (p.34) define #define (define ) (p.61) 1 30 (RD 7 /P SP 7 ) 32 (V DD ) IC

スライド 1

PowerPoint プレゼンテーション

Microsoft Word - 4章.doc

Microsoft Word - テキスト.docx

Microsoft PowerPoint - 第8α章.ppt [互換モード]

PIC

1. 購入物品リスト 電子部品名 用途 規格 単価 数量 合計 購入先 PIC16F84A-20/P PIC16F 秋月電子通商 カーボン抵抗 1/4W R0,R1 10kΩ 秋月電子通商 カーボン抵抗 1/4W R2,R2 追加分 300Ω 秋月

2. アーキテクチャ 概 要 PIC16F8x ファミリは 命 令 語 長 14bit の RISC[1]で 命 令 は35 種 類 である 1 命 令 は4クロックで 実 行 されるが 実 際 にはパイプライン 処 理 [2]されている ノイマン 型 コンピュータ[3]と 違 いプログラムとデータ

PowerPoint プレゼンテーション

Microsoft Word - 組込みプログラミング2018テキスト

スライド 1

Microsoft Word - 工学ゼミ3_テキスト

卒 業 研 究 報 告

BANK1 MOVLW b' ' PIC16F648A独自 MOVWF CMCON コンパレータ OFF BCF INTCON,PEIE 周辺割り込み OFF PIC16F648A独自 MOVLW B' ' RB2/TX, RB1/RX PIC16F648A独自 MOVW

DS30430C-J2-page 2 : 1998 Microchip Technology Inc.

#include "uart.h" // #define RTC8583 0xA0 // RTC address #define CTRL 0x00 // RTC register notation START/STOP #defin

PowerPoint プレゼンテーション

1.1 ラベル ラベルはカラム 1 から始まらなければならない ラベルの後にはコロン スペース タブ 改行が続いてよい ラベルはアルファベットかアンダーバーで始まり 英数字 アンダーバー クエスチョンマークを含んでよい ラベルは 32 文字までである デフォルトではこれらは大文字と小文字を区別するが

PowerPoint プレゼンテーション

Microsoft Word - 工学ゼミ3_テキスト

64 松尾邦昭 2. 無線送受信装置 SANWA 製のラジコン送受信装置は, その機能性の豊富さと価格の安さを理由に多くのラジコン ファンに愛用されており, 今回使用した VG6000は, チャンネル数が6チャンネルあり, ヘリコプター制御用に設計 開発され使用されているものだが, 我々はこれをロボ

実習内容 PIC18C242 のポート B に接続した LED を点滅させます ( 他の実習と同じ内容です ) 8 個の LED に表示される値が +3 ずつインクリメントします MPLAB を使って MPASM アセンブラのソース ファイルをアセンブルします MPLAB とソース ファイルは配布し

序文

も 常に 2 つのコイルに電圧を印加する 2 層励磁方式や 1 つのコイルと 2 つのコイルに交互に電圧を印 2

正転時とは反対に回転する これが逆転である 図 2(d) の様に 4 つのスイッチ全てが OFF の場合 DC モータには電流が流れず 停止する ただし 元々 DC モータが回転していた場合は 惰性でしばらく回転を続ける 図 2(e) の様に SW2 と SW4 を ON SW1 と SW3 を O

#define HOUR 0x04 #define DAY 0x05 #define WEEKDAY 0x06 #define MONTH 0x07 #define YEAR 0x08 #define CKOUT 0x0D #define CTRLT 0x0E // CLKOUT // TIMER

USB モジュール

DS30292A-J-page 2 Preliminary 2000 Microchip Technology Inc. PIC16F876/

BSF PORTA BCF PORTA MOVLWB MOVLWB MOVLWB MOVLWB , E=1, E=0 8 ビット 行表示 ディスプレイ制御 表示クリア エントリーモード CALLDSP MAIN BCF PORTA,3 R

<4D F736F F D C835E838A EA993AE90A78CE CC8A4A94AD2E646F63>

PIC16C7X日本語データシート

1 4 8 (DC) PWM.

i /..12 / / /...22 /

(Making the electronic circuit with use of micro-processor)

main.dvi

PIC

割り込み 今までのプログラムは 順番にそって命令を実行していくのみ それはそれで良いが 不便な場合もある 例えば 時間のかかる周辺機器を使う場合 その周辺機器が動作を終了するまで CPU は待たなければいけない 方法 1( ポーリング ) 一定時間毎に 周辺機器の動作が終了したか調べる 終了していれ

割り込み 今までのプログラムは 順番にそって命令を実行していくのみ それはそれで良いが 不便な場合もある 例えば 時間のかかる周辺機器を使う場合 その周辺機器が動作を終了するまで CPU は待たなければいけない 方法 1( ポーリング ) 一定時間毎に 周辺機器の動作が終了したか調べる 終了していれ

2

2

1 8 Z80 Z GBA ASIC 2 WINDOWS C 1

余白 : 上下 25.4mm, 左右 19mm (Word2012 での やや狭い 設定 ) マイコンプログラミング演習 I レポート 1 実験日 提出日 回路構築 /LED を用いた I/O 制御 [16pt] 班員と担当責任者第 0 班レポート作成

Arduino UNO IS Report No. Report Medical Information System Laboratory

NL-22/NL-32取扱説明書_操作編

2

PIC12C5XX日本語データシート

LC-24_22_19K30.indb

ディジタル電子回路 設計演習課題

by CASIO W61CA For Those Requiring an English/Chinese Instruction

AutomaticTelegraphKeyProject.c

DB0

2

2

REVISION 2.85(6).I 1

2

Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for

VHDL VHDL VHDL i

thesis.dvi

o4hd200j.pdf

PDW-75MD

NL-20取扱説明書_操作編

スライド 1

Microsoft Word - マイコンを用いた信号# doc

NAND FF,,


OAKS16-BoardKit

また RLF 命令は 図 2 示す様に RRF 命令とは逆に 各ビットを一つずつ 左方向に回転 ( ローテイト ) する命令である 8 ビット変数のアドレスを A とし C フラグに 0 を代入してから RLF A,1 を実行すると 変数の内容が 左に 1 ビットシフトし 最下位ビット (LSB)

Taro11-表紙と目次.PDF

TOS7200 CD-ROM DUT PC 1.0X p.15 NEMA Vac/10 A [85-AA-0003] m : CEE7/7 : 250Vac/10 A [85-AA-0005] : GB1002 : 250Vac/10A [ ] 2016

42PHD60123_ p65

2

CM1-GTX

S5U1C8F360T1 Manual (S1C8F360 DEMO Board)


~~~~~~~~~~~~~~~~~~ wait Call CPU time 1, latch: library cache 7, latch: library cache lock 4, job scheduler co

NJW4108 IC ( ) NJW4108 1cell/2cell IC NJW4108V / Bi-CMOS NJW4108V : SSOP20 P-CHG 1 20 Q-CHG NFB 2 19 CS1 CNT 3 18 CS2 GND 4 17 VS NC 5 16 VREF F-CHG 6

RT300i/RT140x/RT105i 取扱説明書

if clear = 1 then Q <= " "; elsif we = 1 then Q <= D; end rtl; regs.vhdl clk 0 1 rst clear we Write Enable we 1 we 0 if clk 1 Q if rst =

(1) BLUETOOTH HT-CT660

3 2 q w e r t y

PRECISION COMPACT DISC PLAYER DP-75V

1 138

スライド 1

Engine Control <D-FH> (T) (T) 0 EDU 0 EFI MIN EDU elay EFI MIN elay 7 0 EFI N. 0 EFI N. - -

EQUIUM EQUIUM S5010 1

Transcription:

卒業研究報告 題 目 PIC プロセッサを用いた多機能ライントレース ロボットの設計と製作 指導教員 綿森道夫助教授 報告者 学籍番号 :1050239 氏名 : 高橋壮平 平成 17 年 2 月 21 日 高知工科大学電子 光システム工学科

PIC - 1 -

- 2 -

PIC - 3 -

/ PIC MPLAB PIC PIC AKI PIC AKI PIC - 4 -

AKI PIC - 5 -

LED LED - 6 -

- 7 - S3 + - BZ1 S2 S1 D12 LED1 D11 LED1 D10 LED1 D9 LED1 D8 LED1 D7 LED1 D6 LED1 D5 LED1 D4 LED1 D3 LED1 D2 LED1 D1 LED1 16F628 RA2 RA3 RA4 RA5 GND RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 Vcc RA6 RA7 RA0 RA1 U1 R3 1k R2 1k R1 1k

PIC A/D USART PIC W-REG STATUS-REG PCHL-REG 3 3 CALL RETURN CALL RETURN - 8 -

bit7 bit0 / TMR1ON - 9 -

= - 10 -

ON VALUE ON? LED 10m - 11 -

- 12 -

VALUE 0 LED - 13 -

movlw b'00110000' movwf t1con ; movlw b'01000000' ; movwf intcon clrf tmr1l ; clrf tmr1h ; movlw b'00001011' movwf ccp1con ; ;**** **** IDLELP BCF PORTA,2 ; BTFSS PORTA,3 ; GOTO STRTKY ; CALL LEDCNT ;LED movlw h'30' ; movwf ccpr1h movlw h'd4' movwf ccpr1l bcf pir1,ccp1if ;ccp1if bsf t1con,tmr1on ; bsf intcon,7 ; - 14 -

bit7 bit0-15 -

- 16 -

0 0 0 255 0 0 OPTION 4 4 0 1 0 4 0 0 PIC CPU 4 1 0 CPU 4 CPU 4 0 INTCON INTCON bit7 bit0-17 -

0-18 -

LED ON OFF PIC * m * - 19 -

BSF STATUS,RP0 MOVLW 000H MOVWF TRISB BCF STATUS,RP0 BCF PORTA,3 ;RA3 = 1 (7seg 10th min) movf c10m,w ;Read 10th of min count movwf bcd_in ;Set count call bcd_7seg ;LED control BSF PORTA,3 bcf PORTA,2 ;RA2 = 1 (7seg 1st min) movf c01m,w ;Read 1st of min count movwf bcd_in ;Set count call bcd_7seg ;LED control BSF PORTA,2 BCF PORTA,1 ;RA1 = 1 (7seg 10th sec) movf c10s,w ;Read 10th of sec count movwf bcd_in ;Set count call bcd_7seg ;LED control BSF PORTA,1 bcf porta,0 ;RA0 = 1 (7seg 1st sec) movf c01s,w ;Read 1st of sec count movwf bcd_in ;Set count call bcd_7seg ;LED control BSF PORTA,0-20 -

- 21 - main sw +3V stop sw start sw 2SC1815 2SC1815 + - BZ1 2SA1015 2SA1015 2SA1015 2SA1015 abcdefg. V+ abcdefg. V+ abcdefg. V+ abcdefg. V+ 16F628 RA2 RA3 RA4 RA5 GND RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 Vcc RA6 RA7 RA0 RA1 U1 BCD-SW 2 1 4 8 BCD-SW 2 1 4 8 10k 10k 240k 240k 140 140 140 140 140 140 140 R5 1k 4.3k 4.3k 3.9k 4.3k

- 22 -

1 00-23 -

YES NO YES NO ON NO NO YES YES - 24 -

ON 10 LED LED 1 BCD 10-25 -

movf c10s,w ;Read 10th of sec counter btfss status,z ;10th of sec is 0? goto countdown ;Jump to countdown movf MIN01,w ;Read 1st of min counter btfss status,z ;1st of min is 0? goto countdown ;Jump to countdown movf MIN10,w ;Read 10th of min counter btfsc status,z ;10th of min is 0? goto piii 1-26 -

1 NO 1 YES 1 NO NO YES YES 10 10 NO 1 YES NO 1 YES YES NO 1 10 NO RETFIE YES ON - 27 -

- 28 -

PIC PWM - 29 -

Vcc Q1 2SJ377 Q2 2SJ377 M1 Q3 2SK2231 Q4 2SK2231 Q1 Q4 ON Q2 Q3 ON Q3 Q4 ON - 30 -

Q1 Q3 Q2 Q4 ON OFF IC IC - 31 -

bit7 bit0-32 -

- 33 -

/ / / / / - 34 -

High Low 150 RPR220 + 10V 20k A 10k 40% - 35 -

Xm sec : 3600 Π dcm : L Lkm / h = 3600 Π dcm / Xmsec = 36 Π d / X msec Xm sec = A 30msec / L = 120 Π d / A = 2035/ A - 36 -

- 37 -

- 38-2SA1015 2SA1015 50k 40% 50k 40% 50k 40% 0.1uF S3 3.0V S1 0.1uF 0.1uF 0.1uF 0.1uF 4MHZ 33uF 0.1uF 0.1uF M1 M2 abcdefg. V+ abcdefg. V+ 74HC00 1in 1in 1out 2in 2in 2out GND 3out 3in 3in 4out 4in 4in Vcc RPR220 RPR220 RPR220 RPR220 RPR220 16F873 MCLR RA0 RA1 RA2 RA3 RA4 RA5 GND OSC1 OSC2 RC0 RC1 RC2 RC3 RC4 RC5 RC6 RC7 GND Vcc RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 MP4207 GND G1 D1 G2 D2 G3 D3 G4 D4 Vcc MP4207 GND G1 D1 G2 D2 G3 D3 G4 D4 Vcc 1in 1out 2in 2out 3in 3out GND 4out 4in 5out 5in 6out 6in Vcc 74HC04 150 120 120 120 10k 10k 5k 5k 5k 5k 4.3k 4.3k 30k 30k 150 150 150 150 130 130 130 130 130 130 130

- 39 -

- 40 -

- 41 -

- 42 -

main btfss porta,0 ; goto w?? ; goto b?? ; w?? btfss porta,1 ; goto ww? ; goto wb? ; ww? btfss porta,2 ; goto back ; goto right ; wb? btfss porta,2 ; goto fowd ; goto right ; b?? btfss porta,1 ; goto bw? ; goto bb? ; bw? btfss porta,2 ; goto left ; goto right ; bb? btfss porta,2 ; goto fowd ; goto right ; - 43 -

left bcf portc,7 ; bsf portc,6 ; movf ccpr1l,w ; addlw d'5' ; btfsc status,c ; movlw h'ff' ; movwf ccpr1l mtr2dwn bcf portc,5 ; bsf portc,4 ; movf ccpr1l,w ; movlw d'5' ; subwf ccpr2l,w btfss status,c ; movlw h'50' ; movwf ccpr2l goto mati1-44 -

High Low - 45 -

movf disp1, w ; call warizan ; movf kekka, w movwf temp movf disp2, w ; call warizan bcf status, c rrf temp, f ; / bcf status, c rrf kekka, f ; / movf temp, w addwf kekka, f ; call henkan ; movf temp, w ; keta1 andlw h'0f' movwf keta1 swapf temp, w ; keta10 andlw h'0f' movwf keta10 / - 46 -

/ - 47 -

PIC PIC PIC CQ PIC - 48 -

- 49 -

;***************************************************** ; ; ; ;****************************************************** LIST P=PIC16F628 ; INCLUDE "P16F628.INC" ;Standard Include File ;Defined System Variables ;********************************* ; ;********************************* CNT1 EQU 020H ;Counter for Timer CNT2 EQU 021H ;Counter for Timer VALUE EQU 023H ;Randomized Data LEDA EQU 024H ;LED position porta LEDB EQU 025H ;LED position portb DIR EQU 030H ; CHK EQU 031H ; WREG EQU 032H STsave EQU 033H wsave EQU 034H ;*********************** ; ;*********************** ORG 0 ;Reset Start GOTO MAIN ORG 4 GOTO WARI MAIN ;***** Initialize ***** 50

bcf status,rp0 ;bank 0 MOVLW 007H MOVWF CMCON BSF STATUS,RP0 ; CLRF TRISB ;PORT B MOVLW 018H ;PORT A MOVWF TRISA ;RA3,4 BSF PCON,3 ; (4.0MHz) movlw movwf b'00000101' pie1 BCF STATUS,RP0 ; MOVLW 02H ; MOVWF LEDA ; CLRF LEDB ; CLRF DIR ; CLRF CHK ; movlw h'07' movwf cmcon ; movlw b'00110000' movwf t1con ; movlw b'01000000' ; movwf intcon clrf tmr1l ; clrf tmr1h ; movlw b'00001011' movwf ccp1con ; ;**** **** IDLELP BCF PORTA,2 ; BTFSS PORTA,3 ; 51

GOTO STRTKY ; CALL LEDCNT ;LED movlw h'30' ; movwf ccpr1h movlw h'd4' movwf ccpr1l bcf pir1,ccp1if ;ccp1if bsf t1con,tmr1on ; bsf intcon,7 ; JUMP BTFSS CHK,2 GOTO JUMP BTFSS CHK,1 GOTO JUMP CLRF CHK BCF INTCON,7 INCF VALUE,F ; GOTO IDLELP ; ;**** ***** STRTKY movlw h'04' movwf ccpr1h movlw h'e2' movwf ccpr1l bcf pir1,ccp1if bsf t1con,tmr1on bsf intcon,7 ;interrupt on JUMP BTFSS CHK,0 GOTO JUMP2 CLRF CHK BCF INTCON,7 BTFSC PORTA,3 ; GOTO IDLELP ; 52

;**** ***** GAMELP BSF PORTA,2 ; ON CALL LEDCNT ;LED INCF VALUE,F ; BTFSS PORTA,4 ; ON GOTO STPKY ; movlw h'04' movwf ccpr1h movlw h'e2' movwf ccpr1l bcf pir1,ccp1if bsf t1con,tmr1on bsf intcon,7 ;interrupt on JUMP3 BTFSS CHK,0 GOTO JUMP3 CLRF CHK BCF INTCON,7 GOTO GAMELP ; ;**** **** STPKY BCF PORTA,2 ; OFF CNTDWN MOVF VALUE,W ; SUBLW 020H ;VALUE 32 BTFSS STATUS,C ;32-W>0? GOTO FIRST ;32 MOVF VALUE,W ; SUBLW 010H ;VALUE 16 BTFSS STATUS,C ;16-W>0? GOTO MIDDLE ;32 GOTO SLOW ;16 ;**** ***** 53

SLOW CALL LEDCNT ;LED BSF PORTA,2 ; ON movlw h'30' movwf ccpr1h movlw h'd4' movwf ccpr1l bcf pir1,ccp1if bsf t1con,tmr1on bsf intcon,7 ;interrupt on JUMP4 BTFSS CHK,1 GOTO JUMP4 CLRF CHK BCF INTCON,7 BCF PORTA,2 ; OFF movlw h'30' movwf ccpr1h movlw h'd4' movwf ccpr1l bcf pir1,ccp1if bsf t1con,tmr1on bsf intcon,7 ;interrupt on JUMP5 BTFSS CHK,2 GOTO JUMP5 CLRF CHK BCF INTCON,7 DECFSZ VALUE,F ;VALUE-1 GOTO CNTDWN ; ;**** **** BCF PORTA,2 ; STPLP BTFSS PORTA,3 ; 54

GOTO STRTKY ; BTFSC PORTA,4 ; GOTO STPLP ; COMF DIR,f ; BTFSS DIR,0 CALL RIGHT BTFSC DIR,0 CALL LEFT GOTO IDLELP ; ;***** **** MIDDLE CALL LEDCNT ;LED BSF PORTA,2 ; ON movlw h'30' movwf ccpr1h movlw h'd4' movwf ccpr1l bcf pir1,ccp1if bsf t1con,tmr1on bsf intcon,7 ;interrupt on JUMP6 BTFSS CHK,1 GOTO JUMP6 CLRF CHK BCF INTCON,7 BCF PORTA,2 ; movlw h'30' movwf ccpr1h movlw h'd4' movwf ccpr1l bcf pir1,ccp1if bsf t1con,tmr1on bsf intcon,7 ;interrupt on 55

JUMP7 BTFSS CHK,1 GOTO JUMP7 CLRF CHK BCF INTCON,7 DECF VALUE,F ;VALUE-1 GOTO CNTDWN ; ;**** FIRST CALL LEDCNT ;LED BSF PORTA,2 ; ON movlw h'04' movwf ccpr1h movlw h'e2' movwf ccpr1l bcf pir1,ccp1if bsf t1con,tmr1on bsf intcon,7 ;interrupt on JUMP8 BTFSS CHK,1 GOTO JUMP8 CLRF CHK BCF INTCON,7 DECF VALUE,F ;VALUE-1 GOTO CNTDWN ;*************************** ; ;*************************** ; ;****************************************** ; ; ;****************************************** LEDCNT 56

;**** LED ***** COMF LEDA,W BTFSC PORTA,2 ; GOTO TESTSET ANDLW 0FBH ; OFF GOTO NEXT TESTSET IORLW 04H ; OFF NEXT MOVWF PORTA COMF LEDB,W ;0,1 MOVWF PORTB ; B ;**** LED **** BTFSC DIR,0 ; GOTO LEFT ; RIGHT RRF LEDA,F ; A RRF LEDB,F ; B BTFSS STATUS,C ; GOTO CLR2 ; BSF LEDA,7 ; goto next1 CLR2 BCF LEDA,7 ; next1 btfss leda,5 goto clr2a bsf leda,1 goto next2 clr2a bcf leda,1 next2 RETURN LEFT RLF LEDB,F ; B RLF LEDA,F ; A btfss status,c goto next5 bsf ledb,0 goto next4 next5 bcf ledb,0 57

next4 BTFSS LEDA,2 ; A 2 GOTO CLR3 ; bsf leda,6 goto next3 CLR3 BCF LEDa,6 NEXT3 RETURN ;**** **** WARI movwf wsave movf status,w movwf stsave bcf pir1,ccp1if incf chk,f movf stsave,w movwf status swapf wsave,f swapf wreg,w retfie END 58

;******************************************************** ; ; ; ;******************************************************** list include p=pic16f628 p16f628.inc ;**************** Label Definition ******************** c10m equ h'20' ;Counter adr (10th min) c01m equ h'21' ;Counter adr ( 1st min) c10s equ h'22' ;Counter adr (10th sec) c01s equ h'23' ;Counter adr ( 1st sec) seg7_0 equ b'01000000' ;-gfedcba Pattern 0 seg7_1 equ b'01111001' ; Pattern 1 seg7_2 equ b'00100100' ; Pattern 2 seg7_3 equ b'00110000' ; Pattern 3 seg7_4 equ b'00011001' ; Pattern 4 seg7_5 equ b'00010010' ; Pattern 5 seg7_6 equ b'00000010' ; Pattern 6 seg7_7 equ b'01111000' ; Pattern 7 seg7_8 equ b'00000000' ; Pattern 8 seg7_9 equ b'00010000' ; Pattern 9 seg70 equ h'30' ;Pattern 0 set adr seg71 equ h'31' ;Pattern 1 set adr seg72 equ h'32' ;Pattern 2 set adr seg73 equ h'33' ;Pattern 3 set adr seg74 equ h'34' ;Pattern 4 set adr seg75 equ h'35' ;Pattern 5 set adr seg76 equ h'36' ;Pattern 6 set adr seg77 equ h'37' ;Pattern 7 set adr seg78 equ h'38' ;Pattern 8 set adr seg79 equ h'39' ;Pattern 9 set adr 59

tm_cnt equ h'40' ;Time adjust counter adr time_f equ h'41' ;Time out flag adr bcd_in equ h'42' ;BCD input area adr w_save equ h'43' ;W Register save adr s_save equ h'44' ;STATUS Register save adr CNT1 equ h'45' ;500usec counter adr CNT2 equ h'46' ;1msec counter adr CNT3 EQU 047H yset EQU 048H ytime EQU 049H MIN01 EQU 050H MIN10 EQU 051H SEC10 EQU 052H SEC01 EQU 053H KAWARI EQU 054H ;**************** Program Start *********************** org 0 ;Reset Vector goto init org 4 ;Interrupt Vector goto int ;**************** Initial Process ********************* init MOVLW 030H MOVWF PORTA CLRF PORTB MOVLW 007H ; MOVWF CMCON bsf status,rp0 ;Change to Bank1 movlw b'00110000' ;RA4/RA5:,RA3-0/RA6/RA7: movwf trisa ;Set PORTA 60

movlw b'00000111' ;RBPU/TOCS/PSA=0,PS=111 movwf option_reg ;Set OPTION_REG bcf status,rp0 ;Change to Bank0 movlw seg7_0 ;Set 7segment pattern 0 movwf seg70 ;Save pattern 0 movlw seg7_1 ;Set 7segment pattern 1 movwf seg71 ;Save pattern 1 movlw seg7_2 ;Set 7segment pattern 2 movwf seg72 ;Save pattern 2 movlw seg7_3 ;Set 7segment pattern 3 movwf seg73 ;Save pattern 3 movlw seg7_4 ;Set 7segment pattern 4 movwf seg74 ;Save pattern 4 movlw seg7_5 ;Set 7segment pattern 5 movwf seg75 ;Save pattern 5 movlw seg7_6 ;Set 7segment pattern 6 movwf seg76 ;Save pattern 6 movlw seg7_7 ;Set 7segment pattern 7 movwf seg77 ;Save pattern 7 movlw seg7_8 ;Set 7segment pattern 8 movwf seg78 ;Save pattern 8 movlw seg7_9 ;Set 7segment pattern 9 movwf seg79 ;Save pattern 9 clrf c10s ;Clear 10th sec counter clrf c01s ;Clear 1st sec counter bsf time_f,0 ;Set time out flag OFF CLRF yset CLRF ytime CLRF MIN10 CLRF MIN01 ;************* Timer stand-by Process ***************** stand_by CLRF C10S CLRF C01S bsf status,rp0 ;Change to Bank1 61

movlw 07FH ;RB6-0:,RB7: movwf TRISB ;Set PORTB BCF STATUS,RP0 MOVLW b'10111111' MOVWF PORTA call t1m ;Wait 1msec MOVFW PORTB XORLW 0FFH andlw h'0f' ;Pick-up digit movwf c10m ;Save 10th of the minute MOVLW B'01111111' MOVWF PORTA ;1st min BCD call t1m ;Wait 1msec MOVFW PORTB XORLW 0FFH andlw h'0f' ;Pick-up digit movwf c01m ;Save 1st of the minute MOVLW B'00111111' MOVWF PORTA call led_cont ;Call LED Countrol sub movf c10m,w ;Read 10th of minute btfss status,z ;10th of min is 0? goto sw_check ;Jump to start sw check movf c01m,w ;Read 1st of minute BTFSC status,z ;1st of min is 0? goto stand_by ;Time is 00:00 SW_CHECK CALL T1M BTFSS PORTA,4 GOTO START BTFSS PORTA,5 GOTO YOREI GOTO STAND_BY 62

;************** Timer start Process ******************* start movlw d'196' ;Set Hard timer value movwf tmr0 ;Set TMR0 movlw d'63' ;Set Soft count value movwf tm_cnt ;Save time adjust movlw h'a0' ;GIE=1,TOIE=1 movwf intcon ;Interruption enable loop call led_cont ;Call LED Countrol sub movf yset,w ;/ btfsc status,z goto yskip movf ytime btfss status,z call piii ;// yskip movf time_f,w ;Read time out flag btfsc status,z ;Time out? goto time_out ;Yes. Jump to time out BTFSC PORTA,5 goto loop ;No. Retry time_out clrf intcon ;Interruptin disable BSF PORTB,7 CALL T2M BCF PORTB,7 goto init ;Jump to Initial Process ;************** LED Control Subroutine **************** led_cont BSF STATUS,RP0 MOVLW 000H 63

MOVWF TRISB BCF STATUS,RP0 BCF PORTA,3 ;RA3 = 1 (7seg 10th min) movf c10m,w ;Read 10th of min count movwf bcd_in ;Set count call bcd_7seg ;LED control BSF PORTA,3 bcf PORTA,2 ;RA2 = 1 (7seg 1st min) movf c01m,w ;Read 1st of min count movwf bcd_in ;Set count call bcd_7seg ;LED control BSF PORTA,2 BCF PORTA,1 ;RA1 = 1 (7seg 10th sec) movf c10s,w ;Read 10th of sec count movwf bcd_in ;Set count call bcd_7seg ;LED control BSF PORTA,1 bcf porta,0 ;RA0 = 1 (7seg 1st sec) movf c01s,w ;Read 1st of sec count movwf bcd_in ;Set count call bcd_7seg ;LED control BSF PORTA,0 return ;******* Change BCD to 7segment data Subroutine ******* bcd_7seg movlw seg70 ;Set 7seg pattern head addwf bcd_in,w ;Pattern table address movwf fsr ;Set table address movf indf,w ;Read 7seg pattern movwf portb ;Set pattern to PORTB 64

CALL T1M return ;************* 1msec Timer Subroutine ***************** T1M MOVLW 0F9H ;1 MOVWF CNT1 ;1+1=2 TIMLP1 NOP DECFSZ CNT1,F ;1+1+2=4 GOTO TIMLP1 ;2+4*249-1=997 RETURN ;997+2=999*1.0usec=0.999msec ;************ Begin Interruption Process ************** int movwf w_save ;Save W register movf status,w ;Read STATUS reg movwf s_save ;Save STATUS reg bcf status,rp0 ;Change to Bank0 btfsc intcon,t0if ;Time out interruption? goto timer_int ;Jump to Timer process ;************ END of Interruption Process ************** int_end movf s_save,w ;Read saved STATUS reg movwf status ;Recover STATUS reg swapf w_save,f ;Read saved W register swapf w_save,w ;Recover W register retfie ;*********** Time-out interruption Process ************ timer_int bcf intcon,t0if ;Clear timer int flag movlw d'196' ;Set Hard timer value movwf tmr0 ;Set TMR0 decfsz tm_cnt,f ;Time over? 65

goto int_end ;No. Retry movlw d'63' ;Set Soft count value movwf tm_cnt ;Save time adjust ;************* Timer count-down Process *************** decfsz c01s,w ;1st of sec is 0 from 1? goto countdown ;No. Jump to countdown ;----------------- Time-out check --------------------- movf c10s,w ;Read 10th of sec counter btfss status,z ;10th of sec is 0? goto countdown ;Jump to countdown movf MIN01,w ;Read 1st of min counter btfss status,z ;1st of min is 0? goto countdown ;Jump to countdown movf MIN10,w ;Read 10th of min counter btfsc status,z ;10th of min is 0? goto piii modori movf c10s,w ;Read 10th of sec counter btfss status,z ;10th of sec is 0? goto countdown ;Jump to countdown movf c01m,w ;Read 1st of min counter btfss status,z ;1st of min is 0? goto countdown ;Jump to countdown movf c10m,w ;Read 10th of min counter btfss status,z ;10th of min is 0? goto countdown ;Jump to countdown time_out1 clrf time_f ;Set time-out flag ON goto int_end ;Return ;---------------- Timer countdown --------------------- countdown 66

movf c01s,w ;Read 1st of sec counter btfss status,z ;1st of sec is 0? goto cd_c01s ;Jump to 1st sec cntdown movlw 9 ;Set 9 movwf c01s ;Save 9 to 1st of sec movf c10s,w ;Read 10th of sec counter btfss status,z ;10th of sec is 0? goto cd_c10s ;Jump to 10th min cntdown movlw 5 ;Set 5 movwf c10s ;Save 5 to 10th of sec ycheck movf c01m,w btfss status,z goto CD_C01M ;Jump to 1st min cntdown movlw 9 ;Set 9 movwf c01m ;Save 9 to 1st of min movf c10m,w ;Read 10th of min counter BTFSS status,z ;10th of min is 0? goto CD_C10M ;Jump to 10th min cntdown goto TIME_OUT1 ;Counter is 00:00 already cd_c01s decf c01s,f ;Count down 1st of sec BSF PORTB,7 CALL T1M CALL T1M BCF PORTB,7 goto int_end ;Return cd_c10s decf c10s,f ;Count down 10th of sec 67

BSF PORTB,7 CALL T1M CALL T1M BCF PORTB,7 goto int_end ;Return cd_c01m decf c01m,f ;Count down 1st of min decf min01,f BSF PORTB,7 CALL T1M CALL T1M BCF PORTB,7 goto int_end ;Return cd_c10m decf c10m,f ;Count down 10th of min decf min10,f BSF PORTB,7 CALL T1M CALL T1M BCF PORTB,7 goto int_end ;Return ;******************************************************** ; END of Count-down timer processing ;******************************************************** T2M MOVLW 001H MOVWF CNT2 MOVLW 008H MOVWF CNT3 MOVLW 001H MOVWF CNT1 TIMLP2 DECFSZ CNT1,F GOTO TIMLP2 68

DECFSZ CNT2,F GOTO TIMLP2 DECFSZ CNT3,F GOTO TIMLP2 RETURN ;******************************************************** ;******************************************************** YOREI bsf status,rp0 ;Change to Bank1 movlw 07FH ;RB6-0:,RB7: movwf TRISB ;Set PORTB BCF STATUS,RP0 MOVLW b'10111111' MOVWF PORTA call t1m ;Wait 1msec MOVFW PORTB XORLW 0FFH andlw h'0f' ;Pick-up digit movwf c10s ;Save 10th of the minute MOVLW B'01111111' MOVWF PORTA ;1st min BCD call t1m ;Wait 1msec MOVFW PORTB XORLW 0FFH andlw h'0f' ;Pick-up digit movwf c01s ;Save 1st of the minute MOVLW B'00111111' MOVWF PORTA call led_cont ;Call LED Countrol sub movf c10s,w ;Read 10th of minute btfss status,z ;10th of min is 0? 69

goto sw_check2 ;Jump to start sw check movf c01s,w ;Read 1st of minute ;BTFSC status,z ;1st of min is 0? ;goto stand_by ;Time is 00:00 SW_CHECK2 CALL T1M BTFSC PORTA,4 GOTO YOREI ESQAPU MOVF C10S,W MOVWF MIN10 MOVF C01S,W MOVWF MIN01 MOVLW 0C0H MOVWF CNT2 MOVLW 0F9H MOVWF CNT1 TIMLP3 NOP DECFSZ CNT1,F GOTO TIMLP3 DECFSZ CNT2,F GOTO TIMLP3 CLRF C10S CLRF C01S GOTO START FINI MOVF PORTB,W MOVWF KAWARI MOVLW 0FFH MOVWF PORTB CALL TITTI MOVF KAWARI,W MOVWF PORTB 70

RETURN NX01 BTFSC MIN01,3 GOTO ZYX BTFSC MIN01,2 GOTO ZYX BTFSC MIN01,1 GOTO ZYX BTFSC MIN01,0 GOTO ZYX DECF MIN01,F RETURN NX10 BTFSC MIN10,3 GOTO ZYX BTFSC MIN10,2 GOTO ZYX BTFSC MIN10,1 GOTO ZYX BTFSC MIN10,0 GOTO ZYX DECF MIN10,F RETURN ZYX RETURN TITTI MOVLW 001H MOVWF CNT2 MOVLW 006H MOVWF CNT3 MOVLW 001H MOVWF CNT1 TIMLP4 DECFSZ CNT1,F GOTO TIMLP4 DECFSZ CNT2,F 71

GOTO TIMLP4 MOVF CNT3,W BTFSC STATUS,Z RETURN PIPPI BTFSS CNT3,0 GOTO YOBI01 GOTO YOBI02 YOBI01 BSF PORTB,7 DECF CNT3,F GOTO TIMLP4 YOBI02 BCF PORTB,7 DECF CNT3,F GOTO TIMLP4 piii bsf portb,7 call t2m bcf portb,7 goto modori end 72

;*************************************************** ; ; by PIC16F873 ; ; ; ;*************************************************** list p=pic16f876 include "p16f876.inc" tmvalueequ h'20' keta10 equ h'21' keta1 equ h'22' count1 equ h'23' count2 equ h'24' mkct1 equ h'25' mark1 equ h'26' disp1 equ h'27' mkct2 equ h'28' mark2 equ h'29' disp2 equ h'2a' temp equ h'2b' waru1 equ h'2c' waru10equ h'2d' kekka equ h'2e' naibu equ h'2f' seg7_0 equ b'10000000' ;gfedcba-pattern 0 seg7_1 equ b'11110010' ; Pattern 1 seg7_2 equ b'01001000' ; Pattern 2 seg7_3 equ b'01100000' ; Pattern 3 seg7_4 equ b'00110010' ; Pattern 4 seg7_5 equ b'00100100' ; Pattern 5 seg7_6 equ b'00000100' ; Pattern 6 seg7_7 equ b'11110000' ; Pattern 7 73

seg7_8 equ b'00000000' ; Pattern 8 seg7_9 equ b'00110000' ; Pattern 9 seg7_a equ b'01000000' ; Pattern a seg7_b equ b'00000110' ; Pattern b seg7_c equ b'10001100' ; Pattern c seg7_d equ b'01000010' ; Pattern d seg7_e equ b'00001000' ; Pattern e seg7_f equ b'00011100' ; Pattern f seg70 equ h'30' ;Pattern 0 set adr seg71 equ h'31' ;Pattern 1 set adr seg72 equ h'32' ;Pattern 2 set adr seg73 equ h'33' ;Pattern 3 set adr seg74 equ h'34' ;Pattern 4 set adr seg75 equ h'35' ;Pattern 5 set adr seg76 equ h'36' ;Pattern 6 set adr seg77 equ h'37' ;Pattern 7 set adr seg78 equ h'38' ;Pattern 8 set adr seg79 equ h'39' ;Pattern 9 set adr seg7a equ h'3a' ;Pattern a set adr seg7b equ h'3b' ;Pattern b set adr seg7c equ h'3c' ;Pattern c set adr seg7d equ h'3d' ;Pattern d set adr seg7e equ h'3e' ;Pattern e set adr seg7f equ h'3f' ;Pattern f set adr w_save equ h'43' ;W Register save adr s_save equ h'44' ;STATUS Register save adr ;**************** Program Start *********************** org 0 ;Reset Vector goto init org 4 ;Interrupt Vector goto tmr1int 74

;**************** Initial Process ********************* init bsf status,rp0 ;bank 1 MOVLW 007H ; MOVWF ADCON1 bcf status, rp0 ; Bank 0 movlw b'00000001' movwf t2con ; TMR2 1:4 clrf tmr2 clrf ccpr1l movlw b'00001100' ; PWM movwf ccp1con movwf ccp2con clrf ccpr1l clrf ccpr2l clrf t1con ; timer1 1:1 clrf pir1 ; flag clear movlw b'01000000' movwf intcon ; PEIE on bsf status,rp0 ;Change to Bank1 movlw b'00111111' ;porta movwf trisa ;Set PORTA clrf trisb ;portb clrf trisc ;portc movlw b'10000011' ; movwf option_reg ;Set OPTION_REG ;PWM movlw h'ff' movwf pr2 movlw b'00000001' movwf pie1 bcf status,rp0 ;Change to Bank0 movlw seg7_0 ;Set 7segment pattern 0 75

movwf seg70 ;Save pattern 0 movlw seg7_1 ;Set 7segment pattern 1 movwf seg71 ;Save pattern 1 movlw seg7_2 ;Set 7segment pattern 2 movwf seg72 ;Save pattern 2 movlw seg7_3 ;Set 7segment pattern 3 movwf seg73 ;Save pattern 3 movlw seg7_4 ;Set 7segment pattern 4 movwf seg74 ;Save pattern 4 movlw seg7_5 ;Set 7segment pattern 5 movwf seg75 ;Save pattern 5 movlw seg7_6 ;Set 7segment pattern 6 movwf seg76 ;Save pattern 6 movlw seg7_7 ;Set 7segment pattern 7 movwf seg77 ;Save pattern 7 movlw seg7_8 ;Set 7segment pattern 8 movwf seg78 ;Save pattern 8 movlw seg7_9 ;Set 7segment pattern 9 movwf seg79 ;Save pattern 9 movlw seg7_a movwf seg7a movlw seg7_b movwf seg7b movlw seg7_c movwf seg7c movlw seg7_d movwf seg7d movlw seg7_e movwf seg7e movlw seg7_f movwf seg7f ;***************************************** ; ; 76

; ;***************************************** start clrf keta10 clrf keta1 clrf mkct1 clrf mark1 clrf mkct2 clrf mark2 clrf disp1 clrf disp2 movlw d'50' movwf count1 movwf count2 bsf t2con, tmr2on ; tmr2 clrf tmr0 movlw b'10000111' movwf porta clrf portb movlw h'd0' movwf tmr1l movlw h'8a' movwf tmr1h bsf t1con, tmr1on bsf intcon, gie loop movlw seg70 ;Set 7seg pattern head addwf keta1,w ;Pattern table address movwf fsr ;Set table address movf indf,w ;Read 7seg pattern btfss portb, 3 andlw b'11110111' movwf portb ;Set pattern to PORTB 77

movlw b'00001001' iorwf portc, f bcf portc, 3 goto main mati1 nop ; TMR0 tmr1lp btfss goto bcf intcon, t0if tmr1lp intcon, t0if movlw seg70 ;Set 7seg pattern head addwf keta10,w ;Pattern table address movwf fsr ;Set table address movf indf,w ;Read 7seg pattern btfss portb, 3 andlw b'11110111' movwf portb ;Set pattern to PORTB movlw b'00001001' iorwf portc, f bcf portc, 0 decfsz count2, f goto tmr2lp movlw d'15' movwf count2 movf disp1, w ; call warizan ; movf kekka, w movwf temp movf disp2, w ; call warizan bcf status, c 78

rrf temp, f ; / bcf status, c rrf kekka, f ; / movf temp, w addwf kekka, f ; call henkan ; movf temp, w ; keta1 andlw h'0f' movwf keta1 swapf temp, w ; keta10 andlw h'0f' movwf keta10 ; TMR0 tmr2lp btfss goto bcf intcon, t0if tmr2lp intcon, t0if goto loop ;************************************************* ; ; warizan program (2000 / disp1 ) -> kekka ; kekka -> 16 shinnsuu 2 keta ;************************************************* warizan movwf naibu movlw h'07' movwf waru10 79

movlw h'd0' movwf waru1 clrf kekka movlw d'21' subwf naibu, w btfss status, c goto waruzero hiku movf naibu, w subwf waru1, f btfsc status, c goto plus movf waru10, w btfsc status, z return decf waru10, f plus incf kekka, f goto hiku waruzero clrf kekka return ;********************************************* ; ; henkan program 16 shin -> 10 shin ; ;********************************************* henkan clrf movf btfsc return temp kekka, w status, z tasu1 incf movf temp, f temp, w 80

andlw h'0f' sublw h'0a' btfss status, z goto tasu2 swapf temp, f movlw h'0f' andwf temp, f incf temp, f swapf temp, f tasu2 decfsz kekka, f goto tasu1 return ;********************************************* ; ; timer1 interrupt routine ; ;********************************************* tmr1int movwf w_save movf status, w movwf s_save btfss pir1, tmr1if goto intend bcf pir1, tmr1if bcf t1con, tmr1on movlw h'd0' movwf tmr1l movlw h'8a' movwf tmr1h bsf t1con, tmr1on btfss porta, 4 goto whitemk1 movf mark1, w 81

btfss status, z clrf mark1 movlw d'166' subwf mkct1, w btfss status, c goto blackmk1 movlw h'ff' movwf mkct1 goto leftport blackmk1 incf mkct1, f goto leftport whitemk1 movf btfsc goto incf btfsc decf goto mark1, w status, z zeromk1 mkct1, f status, z mkct1, f leftport zeromk1 bsf mark1, 0 movf mkct1, w movwf disp1 clrf mkct1 leftport movlw h'ff' subwf mkct1, w btfss status, z goto left3 movlw h'00' movwf disp1 left3 btfss porta, 5 82

goto whitemk2 movf mark2, w btfss status, z clrf mark2 movlw d'166' subwf mkct2, w btfss status, c goto blackmk2 movlw h'ff' movwf mkct2 goto left2 blackmk2 incf mkct2, f goto left2 whitemk2 movf btfsc goto incf btfsc decf goto mark2, w status, z zeromk2 mkct2, f status, z mkct2, f left2 zeromk2 bsf mark2, 0 movf mkct2, w movwf disp2 clrf mkct2 left2 movlw h'ff' subwf mkct2, w btfss status, z goto intend movlw h'00' movwf disp2 83

intend movf disp1, w movwf temp movf s_save, w movwf status swapf w_save, f swapf w_save, w retfie ;*************************************** ; ; ; ;*************************************** main btfss porta,0 ; goto w?? ; goto b?? ; w?? btfss porta,1 ; goto ww? ; goto wb? ; ww? btfss porta,2 ; goto back ; goto right ; wb? btfss porta,2 ; goto fowd ; goto right ; b?? btfss porta,1 ; goto bw? ; goto bb? ; 84

bw? btfss porta,2 ; goto left ; goto right ; bb? btfss porta,2 ; goto fowd ; goto right ; ;*************************************** ; ;*************************************** left bcf portc,7 ; bsf portc,6 ; movf ccpr1l,w ; addlw d'5' ; btfsc status,c ; movlw h'ff' ; movwf ccpr1l mtr2dwn bcf portc,5 ; bsf portc,4 ; movf ccpr1l,w ; movlw d'5' ; subwf ccpr2l,w btfss status,c ; movlw h'50' ; movwf ccpr2l goto mati1 right bcf portc,5 ; bsf portc,4 ; movf ccpr2l,w ; addlw d'5' ; btfsc status,c ; 85

movlw H'ff' ; movwf ccpr2l mtr1dwn bcf portc,7 ; bsf portc,6 ; movf ccpr1l,w ; movlw d'5' ; subwf ccpr1l,w btfss status,c ; movlw h'50' ; movwf ccpr1l goto mati1 fowd ; call right12 call left12 goto mati1 right12 bcf portc,7 ; bsf portc,6 ; movf ccpr1l,w ; addlw d'5' ; btfsc status,c ; movlw h'ff' ; movwf ccpr1l return left12 bcf portc,5 ; bsf portc,4 ; movf ccpr2l,w ; addlw d'5' ; btfsc status,c ; movlw H'ff' ; movwf ccpr2l return back 86

call call goto rmtr1 rmtr2 mati1 rmtr1 rmtr2 bcf portc,6 bsf portc,7 movlw h'80' movwf ccpr1l addlw d'5' btfsc status,c movlw H'ff' movwf ccpr1l return bcf portc,4 bsf portc,5 movlw h'80' movwf ccpr2l addlw d'5' btfsc status,c movlw H'ff' movwf ccpr2l return END 87