您当前的位置:五五电子网电子知识单片机-工控设备PIC单片机PIC单片机玩具车程序 正文
PIC单片机玩具车程序

PIC单片机玩具车程序

点击数:7448 次   录入时间:03-04 11:39:06   整理:http://www.55dianzi.com   PIC单片机

PIC 单片机 玩具车程
  LIST P=12CE519, R=DEC
INCLUDE <P12CE519.INC>
  __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_ON & _IntRC_OSC 
;--------------------------------------------------------------------


#DEFINE INOUT 00001000b ; GPIO port input/output definition
#DEFINE DCCIN GPIO,3  ; DCC input PIN (GPIO,3 only input)




#DEFINE MOTOR1 GPIO,0  ; motor
#DEFINE MOTOR2 GPIO,1  ; output




#DEFINE LIGHT1 GPIO,4  ; light
#DEFINE LIGHT2 GPIO,5  ; output




#DEFINE LED GPIO,2  ; redlight, flickering firebox




;--------------------------------------------------------------------
CV8 EQU 0x0D ; Home Made Decoder
CV7 EQU 0x09 ; Version No.  XX00 0000
   ; 00=Analog(0x00) 01=Stepper(0x40)
   ; 10=Fauli(0x80)  11=Other(0xC0)
TFLKON EQU 60 ; flickering firebox ontime
;--------------------------------------------------------------------
INDF EQU 0x00 ; Indirect Adressing
tmr0 EQU 0x01 ; Timer
PC EQU 0x02 ; Programm Counter
STATUS EQU 0x03 ; Status Register
FSR EQU 0x04 ; Special Funcion Register
OSCCAL EQU 0x05 ; Calibration Register
GPIO EQU 0x06 ; GP0-GP5 input/output
;--------------------
S31 EQU 0x07 ;
CONFIG EQU 0x08 ; 0=DIR 1=CONSIST 2=STEPOK/NOCV 5=FS126 6=BITHI 7=FLAG
SOLL EQU 0x09 ; speed to go
BT1 EQU 0x0A ; FSR auf 0x09
BT2 EQU 0x0B ;
BT3 EQU 0x0C ;
BT4 EQU 0x0D ;
BT5 EQU 0x0E ;
BT6 EQU 0x0F ; FSR auf 0x10
;--------------------
; EQU 0x10 ;
; EQU 0x11 ;
ACC EQU 0x12 ;
DEC EQU 0x13 ;
; EQU 0x14 ;
TFLKOFF EQU 0x15 ; flickering firebox offtime
FLAG EQU 0x16 ;
; EQU 0x17 ;
XOR EQU 0x18 ;
NOADR EQU 0x19 ; no adress since ... 
PWM EQU 0x1A ; (Z1)
F1F8SET EQU 0x1B ;
IST EQU 0x1C ; actual speed
PRE EQU 0x1D ; Preample 12 BIT
LO EQU 0x1E ; low bit counter
HI EQU 0x1F ; hi bit counter
;--------------------
CV1 EQU 0x30 ; Primary Adress
CV2 EQU 0x31 ; Vstart
CV3 EQU 0x32 ; Acceleration Rate
CV4 EQU 0x33 ; Deceleration Rate
CV29 EQU 0x34 ; 0=DIR 1=14/28 2=PWRSRC 3=ADVACK 4=SPDTAB 5=LADRE 6= 7=ACCDEC
MAPCV EQU 0x35 ; rom CV’s copied to here
CV5 EQU 0x36 ; Vhigh
CV6 EQU 0x37 ; Vmid
CV17 EQU 0x38 ; Extended Adress Low Byte
CV18 EQU 0x39 ; Extended Adress High Byte
CV19 EQU 0x3A ; Consist Adress
CV49 EQU 0x3B ; Output F1-F8 to GP2 (CV49-64)
CV50 EQU 0x3C ; Output F1-F8 to GP4
CV51 EQU 0x3D ; Output F1-F8 to GP5
CV55 EQU 0x3E ; Vmax 2
CV64 EQU 0x3F ; configuration byte
;---------------------
#DEFINE FLOFF CV64,0  ; front light switch with cv50 (GP4)
#DEFINE RANGIER CV64,0  ; low activ, mapped with FLOFF
#DEFINE BLOFF CV64,1  ; back light switch with cv51 (GP5)
#DEFINE SPEED2 CV64,1  ; low activ, mapped with BLOFF
#DEFINE RDLTON CV64,2  ; red light on (back light)
#DEFINE BRKON CV64,3  ; brake light on
#DEFINE HI2LOFS CV64,4  ; convert 126FS to 28FS with Vmin/Vmid/Vmax
#DEFINE FLACKON CV64,5  ; flickering firebox
#DEFINE LITAUTO CV64,6  ; firebox open/close automatically
#DEFINE REDLT CV64,7  ; is set by program
;---------------------
CARRY EQU 0
ZERO EQU 2
SEITE EQU 5




#DEFINE DIR CONFIG,0 ;
#DEFINE CONSIST CONFIG,1 ;
#DEFINE STEPOK? CONFIG,2 ;
#DEFINE NOCV CONFIG,2 ; is mapped with STEPOK?
#DEFINE ROMCV CONFIG,3 ; is mapped with FLACKER
#DEFINE FLACKER CONFIG,3 ;
#DEFINE BRAKE CONFIG,4 ;
#DEFINE FS126 CONFIG,5 ;
#DEFINE BITHI CONFIG,6 ;
#DEFINE FLAGS2 CONFIG,7 ;




#DEFINE LITOPEN FLAG,6  ; for lit open/close (copy from CV64)




#DEFINE DIRINV CV29,0  ; direction inverted (+light)
#DEFINE FS28 CV29,1  ; 14/28 speed step
#DEFINE LIINV CV29,2  ; light inverted (PWRSRC never used)
#DEFINE STAB CV29,4  ; speedtab / CV2,CV5&CV6
#DEFINE LADRE CV29,5  ; long adress enable
#DEFINE PROGBIT CV29,6  ;
#DEFINE PROGBT1 CV29,7  ;




#DEFINE ACKBIT STATUS,6 ; never overwriten




;--------------------------------------------------------------------
ORG     0  ; Reset Vector




INIT  MOV LW 00001000b ; CALFST on
MOV WF OSCCAL  ; write calibration value




MOV LW 11010001b ; no wakeup, no pullup, T0 int., hightolow, T0, 1:4
OPTION




;.....................................................................
CALI BTFSS DCCIN  ;-----------------
GOTO CALI  ; Anfang
CALI1 BTFSC DCCIN  ; finden
GOTO CALI1  ;-----------------
CLRF tmr0  ; Timer auf 0
CALI2 BTFSS DCCIN  ;
GOTO CALI2  ;-----------------
MOV F tmr0,0  ; Timer 
MOV WF BT5  ; sichern
MOV LW 34  ;-----------------

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  下一页


本文关键字:单片机  程序  玩具  PIC单片机单片机-工控设备 - PIC单片机

上一篇:LCD1602显示C语言