用PIC12C508A控制模型源程序

2019-10-23来源: eefocus关键字:PIC12C508A  控制模型  12C508A

; Description: Receive IR Remote control NEC code
list p=12C508A, f=INHX8M, r=DEC, b=8, C=80
__config (_MCLRE_OFF & _CP_ON & _WDT_OFF & _IntRC_OSC)
__idlocs H'0001'

INDF equ 0x00
TMR0 equ 0x01
PCL equ 0x02
STATUS equ 0x03
FSR equ 0x04
OSCCAL equ 0x05
GPIO equ 0x06

Bit7 equ 0x07
Bit6 equ 0x06
Bit5 equ 0x05
Bit4 equ 0x04
Bit3 equ 0x03
Bit2 equ 0x02
Bit1 equ 0x01
Bit0 equ 0x00

W equ 0x00
F equ 0x01

; STATUS Register
GPWUF equ Bit7
PA0 equ Bit5
NOT_TO equ Bit4
NOT_PD equ Bit3
Z equ Bit2
DC equ Bit1
C equ Bit0

; GPIO Register
bIRDataIn equ Bit0
bSystemPowerOut0 equ Bit1

; Configuration Bits
_MCLRE_ON equ 0x0fff
_MCLRE_OFF equ 0x0fef
_CP_ON equ 0x0ff7
_CP_OFF equ 0x0fff
_WDT_ON equ 0x0fff
_WDT_OFF equ 0x0ffb
_LP_OSC equ 0x0ffc
_XT_OSC equ 0x0ffd
_IntRC_OSC equ 0x0ffe
_ExtRC_OSC equ 0x0fff

; Macro Definition
PowerDownSystem MACRO
bcf GPIO, bSystemPowerOut0
ENDM

PowerUpSystem MACRO
bsf GPIO, bSystemPowerOut0
ENDM

; General Purpose Register
DelayCounter1 equ 0x07
DelayCounter2 equ 0x08

AddrCode equ 0x10
AddrCodeNot equ 0x11
DataCode equ 0x12
DataCodeNot equ 0x13

Result equ 0x14
PowerState equ 0x15
ButtonTemp equ 0x16

Bit equ 0x17
GetBitCounter equ 0x18
GetBitCountLo equ 0x19
GetBitCountHi equ 0x1A
PausecountLo equ 0x1B
PausecountHi equ 0x1C
errorflag equ 0x1D
; Constant Definition
cPowerOn equ 0xFF
cPowerOff equ 0x00
cPowerHi equ 0x82
cPowerLo equ 0x7D
cAddressHi equ 0xF0
cAddressLo equ 0x0F
;==============================================================================
org 0000h
movwf OSCCAL
goto main
;------------------------------------------------------------------------------
; Function: pDelay1ms
; Overview: This is a very accurate 1ms delay for a 4MHz clock.
;------------------------------------------------------------------------------
pDelay1ms:
movlw .198
movwf DelayCounter1
nop
nop
tagDelay1ms_01:
nop
nop
decfsz DelayCounter1, F
goto tagDelay1ms_01
retlw 0x00
;------------------------------------------------------------------------------
; Function: pDelay250ms
; Overview:
;------------------------------------------------------------------------------
pDelay250ms:
movlw .250
movwf DelayCounter2
tagDelay250ms_01:
call pDelay1ms
decfsz DelayCounter2, F
goto tagDelay250ms_01
retlw 0x00

;------------------------------------------------------------------------------
; Function: pGetBit
; Overview:
;------------------------------------------------------------------------------
pGetBit:
tagBitStart:
clrf errorflag
clrf GetBitCountLo
clrf GetBitCountHi

tagBitWait:
btfss GPIO, bIRDataIn
goto tagBitWait

tagBitLoop:
incfsz GetBitCountLo, F
goto tagBitNext
incf GetBitCountHi, F
movlw .3
subwf GetBitCountHi,W
btfsc STATUS,C
goto errorret
tagBitNext:
btfsc GPIO, bIRDataIn
goto tagBitLoop

movlw .1
subwf GetBitCountHi, W
btfsc STATUS, Z
goto tagBitIsOne

tagBitIsZero:
movlw 0x00
movwf Bit
goto tagBitDone
tagBitIsOne:
movlw 0xff
movwf Bit
goto tagBitDone

tagBitDone:
retlw 0x00
errorret:
bsf errorflag,Bit0
retlw 0x00
;------------------------------------------------------------------------------
;==============================================================================
; Program Main Entry.
;==============================================================================
main:
movlw B'11000111'
option

movlw B'11111101'
tris GPIO

;PowerUpSystem
movlw B'11111111'
movwf GPIO

movlw cPowerOn
movwf PowerState

initial:
clrf AddrCode
clrf AddrCodeNot
clrf DataCode
clrf DataCodeNot

doIrCheck:
btfsc GPIO, bIRDataIn
goto doIrCheck

;================================================
;call pGetBit
leaderWait:
btfss GPIO, bIRDataIn
goto leaderWait
call pGetBit
pauseWait:
;btfsc GPIO, bIRDataIn
;goto pauseWait
movf GetBitCountLo,W
movwf PausecountLo
movf GetBitCountHi,W
movwf PausecountHi
movlw 0x02
subwf PausecountHi,W
btfss STATUS,Z
;btfss PausecountHi,Bit1
goto doIrCheck
;btfsc GPIO,bIRDataIn
;goto

;================================================
AddrBit0:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrBit0Zero

AddrBit0One:
bsf AddrCode, Bit0
goto AddrBit1

AddrBit0Zero:
bcf AddrCode, Bit0
;------------------------------------------------
AddrBit1:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrBit1Zero

AddrBit1One:
bsf AddrCode, Bit1
goto AddrBit2

AddrBit1Zero:

bcf AddrCode, Bit1
;------------------------------------------------
AddrBit2:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrBit2Zero

AddrBit2One:
bsf AddrCode, Bit2
goto AddrBit3

AddrBit2Zero:
bcf AddrCode, Bit2
;------------------------------------------------
AddrBit3:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrBit3Zero

AddrBit3One:
bsf AddrCode, Bit3
goto AddrBit4

AddrBit3Zero:
bcf AddrCode, Bit3
;------------------------------------------------
AddrBit4:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrBit4Zero

AddrBit4One:
bsf AddrCode, Bit4
goto AddrBit5

AddrBit4Zero:
bcf AddrCode, Bit4
;------------------------------------------------
AddrBit5:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrBit5Zero

AddrBit5One:
bsf AddrCode, Bit5
goto AddrBit6

AddrBit5Zero:
bcf AddrCode, Bit5
;------------------------------------------------
AddrBit6:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrBit6Zero

AddrBit6One:
bsf AddrCode, Bit6
goto AddrBit7

AddrBit6Zero:
bcf AddrCode, Bit6
;------------------------------------------------
AddrBit7:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrBit7Zero

AddrBit7One:
bsf AddrCode, Bit7
goto AddrNotBit0

AddrBit7Zero:
bcf AddrCode, Bit7
;++++++++++++++++++++++++++++++++++++++++++++++++
AddrNotBit0:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrNotBit0Zero

AddrNotBit0One:
bsf AddrCodeNot, Bit0
goto AddrNotBit1

AddrNotBit0Zero:
bcf AddrCodeNot, Bit0
;------------------------------------------------
AddrNotBit1:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrNotBit1Zero

AddrNotBit1One:
bsf AddrCodeNot, Bit1
goto AddrNotBit2

AddrNotBit1Zero:

bcf AddrCodeNot, Bit1
;------------------------------------------------
AddrNotBit2:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrNotBit2Zero

AddrNotBit2One:
bsf AddrCodeNot, Bit2
goto AddrNotBit3

AddrNotBit2Zero:
bcf AddrCodeNot, Bit2
;------------------------------------------------
AddrNotBit3:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrNotBit3Zero

AddrNotBit3One:
bsf AddrCodeNot, Bit3
goto AddrNotBit4

AddrNotBit3Zero:
bcf AddrCodeNot, Bit3
;------------------------------------------------
AddrNotBit4:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrNotBit4Zero

AddrNotBit4One:
bsf AddrCodeNot, Bit4
goto AddrNotBit5

AddrNotBit4Zero:
bcf AddrCodeNot, Bit4
;------------------------------------------------
AddrNotBit5:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrNotBit5Zero

AddrNotBit5One:
bsf AddrCodeNot, Bit5
goto AddrNotBit6

AddrNotBit5Zero:
bcf AddrCodeNot, Bit5
;------------------------------------------------
AddrNotBit6:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrNotBit6Zero

AddrNotBit6One:
bsf AddrCodeNot, Bit6
goto AddrNotBit7

AddrNotBit6Zero:
bcf AddrCodeNot, Bit6
;------------------------------------------------
AddrNotBit7:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto AddrNotBit7Zero

AddrNotBit7One:
bsf AddrCodeNot, Bit7
goto DataBit0

AddrNotBit7Zero:
bcf AddrCodeNot, Bit7
;++++++++++++++++++++++++++++++++++++++++++++++++
DataBit0:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataBit0Zero

DataBit0One:
bsf DataCode, Bit0
goto DataBit1

DataBit0Zero:
bcf DataCode, Bit0
;------------------------------------------------
DataBit1:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataBit1Zero

DataBit1One:
bsf DataCode, Bit1
goto DataBit2

DataBit1Zero:

bcf DataCode, Bit1
;------------------------------------------------
DataBit2:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataBit2Zero

DataBit2One:
bsf DataCode, Bit2
goto DataBit3

DataBit2Zero:
bcf DataCode, Bit2
;------------------------------------------------
DataBit3:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataBit3Zero

DataBit3One:
bsf DataCode, Bit3
goto DataBit4

DataBit3Zero:
bcf DataCode, Bit3
;------------------------------------------------
DataBit4:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataBit4Zero

DataBit4One:
bsf DataCode, Bit4
goto DataBit5

DataBit4Zero:
bcf DataCode, Bit4
;------------------------------------------------
DataBit5:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataBit5Zero

DataBit5One:
bsf DataCode, Bit5
goto DataBit6

DataBit5Zero:
bcf DataCode, Bit5
;------------------------------------------------
DataBit6:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataBit6Zero

DataBit6One:
bsf DataCode, Bit6
goto DataBit7

DataBit6Zero:
bcf DataCode, Bit6
;------------------------------------------------
DataBit7:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataBit7Zero

DataBit7One:
bsf DataCode, Bit7
goto DataNotBit0

DataBit7Zero:
bcf DataCode, Bit7
;++++++++++++++++++++++++++++++++++++++++++++++++
DataNotBit0:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataNotBit0Zero

DataNotBit0One:
bsf DataCodeNot, Bit0
goto DataNotBit1

DataNotBit0Zero:
bcf DataCodeNot, Bit0
;------------------------------------------------
DataNotBit1:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataNotBit1Zero

DataNotBit1One:
bsf DataCodeNot, Bit1
goto DataNotBit2

DataNotBit1Zero:

bcf DataCodeNot, Bit1
;------------------------------------------------
DataNotBit2:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataNotBit2Zero

DataNotBit2One:
bsf DataCodeNot, Bit2
goto DataNotBit3

DataNotBit2Zero:
bcf DataCodeNot, Bit2
;------------------------------------------------
DataNotBit3:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataNotBit3Zero

DataNotBit3One:
bsf DataCodeNot, Bit3
goto DataNotBit4

DataNotBit3Zero:
bcf DataCodeNot, Bit3
;------------------------------------------------
DataNotBit4:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataNotBit4Zero

DataNotBit4One:
bsf DataCodeNot, Bit4
goto DataNotBit5

DataNotBit4Zero:
bcf DataCodeNot, Bit4
;------------------------------------------------
DataNotBit5:
call pGetBit
btfsc errorflag,Bit0
goto doIrCheck
btfss Bit, Bit7
goto DataNotBit5Zero

[1] [2]
关键字:PIC12C508A  控制模型  12C508A 编辑:什么鱼 引用地址:http://news.eeworld.com.cn/mcu/ic478035.html 本网站转载的所有的文章、图片、音频视频文件等资料的版权归版权所有人所有,本站采用的非本站原创文章及图片等内容无法一一联系确认版权者。如果本网所选内容的文章作者及编辑认为其作品不宜公开自由传播,或不应无偿使用,请及时通过电子邮件或电话通知我们,以迅速采取适当措施,避免给双方造成不必要的经济损失。

上一篇:PIC16C712功能、特点、应用领域与替代16C711方法、注意事项
下一篇:16c54四位LED时钟显示程序

关注eeworld公众号 快捷获取更多信息
关注eeworld公众号
快捷获取更多信息
关注eeworld服务号 享受更多官方福利
关注eeworld服务号
享受更多官方福利

推荐阅读

pic16f877a对24c01的读写程序
#i nclude<pIC.h>#i nclude<string.h>#define uchar  unsigned char#define uint   unsigned intstatic volatile unsigned char aCC @ 0x20;            //发收数据暂存器static volatile bit acc0     @ (unsigned)&acc*8+0; 
发表于 2017-12-10
PIC16f877A读写24c01的程序
#include<pIC.h> #include<string.h> #define uchar  unsigned char #define uint   unsigned int static volatile unsigned char aCC @ 0x20;            //发收数据
发表于 2017-12-07
PIC16f877A读写24c02程序
PIC16f877A读写24c02程序#include<pic.h>  #include<string.h>  #define uchar  unsigned char  #define uint   unsigned int static volatile unsigned char aCC @ 0x20;       
发表于 2017-12-07
pic16f877A软件模拟I2C通信读写24C02
;该试验功能是 单片机 复位一次,自动从24C02中读取数据到数码管显示,然后对值加1再写入24C02,最终数码管中的数据就是开机的次数,具有一定的实用意义 ;本电路所使用24C02为ATMEL的,或不是该厂的,则烧写时间可能会有差异 ;必须调整本程序的DELAY时间 ;本实战的目的是让大家进上步熟悉I2C通信的时序,熟悉24CXX的读写,会用软件模拟I2C通信;硬件接法: ;1.24CXX的SDA接877A的RB5口,SCLK接877A的RB4口,WP接地,A0,A1,A2接地LIST      P
发表于 2017-12-06
PIC12C508A单片机的编程再写
  第一次用PIC12C508A芯片制作的振荡器,其源程序为PIC01.ASM,占用程序存储器空间是从D'30‘开始的地址存放的程序,全部程序共占22个地址;第二次再写时,用同一芯片PIC12C508A.也是一种振荡器,振荡频率比前者低(以便观察),其源程序定义为PIC03.ASM,其清单如下:    LIST P=12C508A;选芯片型号。    INCLUDE P12C508A。INCCOUNTl EQU 08H;自定义寄存器地址。  END    :程序结束    说明:由以上的源程序可看出,PIC12C508A再写时,需在ORG 0(复位矢量)之后增加一条空指令,且程序是从D'56
发表于 2017-12-03
PIC12C508A单片机的编程再写
高清晰LED显示控制模型设计分析
2路HDMI输入,所以输入总带宽为一路的2倍,即7.6 Gbps,显然,7.6 Gbps的两倍要远大于9.9Gbps,因此DDRSDRAM必须扩展其位宽到60bit,从而增加其数据吞吐速率。高清晰LED显示控制模型设计分析2013-03-18 16:49      文章来源:  电源网      有3184人阅读过  图4. 乒乓操作系统输入端数据处理如图4所示,两路HDMI输入采用乒乓操作,共需要4块512x30bit的RAM。每块RAM对于DDR SDRAM
发表于 2013-11-24
高清晰LED显示控制模型设计分析
小广播
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号 电信业务审批[2006]字第258号函 京公海网安备110108001534 Copyright © 2005-2019 EEWORLD.com.cn, Inc. All rights reserved