EDN首页   博客首页

2

关于投票
nRF9E5 RTC 中断程序

设置了初始化和中断,如果进入RTC中断的话外部的LED应该是可以闪烁的。

void Init(void)
{
  unsigned char cklf;

  TH1 = 243;                 // 19200@16MHz (when T1M=1 and SMOD="1")
  CKCON |= 0x10;           // T1M=1 (/4 timer clock)
  PCON = 0x80;             // SMOD="1" (double baud rate)
  SCON = 0x52;             // Serial mode1, enable receiver
  TMOD = 0x20;             // Timer1 8bit auto reload
  TR1 = 1;                   // Start timer1
  P0_ALT |= 0x06;           // Select alternate functions on pins P0.1 P0.2
  P0_DIR |= 0x02;           // P0.1 (RxD) is input

  SPICLK = 5;               // SPI clock
  SPI_CTRL = 0x02;           // Connect internal SPI controller to Radio

  // Switch to 16MHz clock:
  RACSN = 0;
  SpiReadWrite(RRC | 0x09);
  cklf = SpiReadWrite(0) | 0x04;
  RACSN = 1;
  RACSN = 0;
  SpiReadWrite(WRC | 0x09);
  SpiReadWrite(cklf);
  RACSN = 1;
}

void RTC_init(void)
{
  TICK_DV=0x05;
  while((REGX_CTRL&0x10)!=0){;}
  REGX_MSB = 0x01;
  REGX_LSB = 0xff;
  REGX_CTRL= 0x0A;
}

bit led="0";
void RTC_ISR(void) interrupt 12
{
  WDTI =0;
  led=!led;
  P04=led;
}

void main(void)
{
  P0_ALT = 0x00;
  P0_DIR = 0xAF;
  Init();
  EWDI=1;
  EA = 1;
  Delay100us(255);
  for (;
  {
  }
}

系统分类: 单片机
用户分类: 嵌入式系统开发
标签: nRF9E5 RTC 低频唤醒定时器
来源: 转贴
发表评论 阅读全文(282) | 回复(0)

1

关于投票
无线单片机nRF9E5的看门狗程序设计

void CLRWDT(void)//初始化及喂狗
{
       while ((REGX_CTRL & 0x10));
       REGX_MSB = 0x0f;
       REGX_LSB = 0xff;  //看门狗定时值
       REGX_CTRL = 0x08;  //写入看门狗
}

--------------------------------------------------------------------------------------------------

16.5  Watchdog

The watchdog is activated on the first write to its control register SFR 0xAD. It can not be disabled by any other means than a reset. The watchdog register is loaded by writing a 16-bit value to the two 8-bit data registers (SFR 0xAB and 0xAC) and then the writing the correct opcode to the control register. The watchdog will then count down towards 0 and when 0 is reached the complete microcontroller will be reset To avoid the reset, the software must load new values into the watchdog register sufficiently often.

16.6  Programming Interface to Watchdog and Wakeup Functions

RTC timer GPIO wakeup and Watchdog are controlled via SFRs 0xAB, 0xAC and 0xAD.Typical sequences are:
Write: Wait until REGX_CRTL.4 == 0 (i.e. not busy)
Write REGX_MSB, Write REGX_LSB, Write REGX_CTRL
Read: Wait until REGX_CRTL.4 == 0 (i.e. not busy)
Write REGX_CTRL, Wait until REGX_CRTL.4 == 0 (i.e. not busy)
Read REGX_MSB, Read REGX_LSB

系统分类: 单片机
用户分类: 嵌入式系统开发
标签: nRF9E5 Watchdog 看门狗
来源: 整理
发表评论 阅读全文(570) | 回复(2)

1

关于投票
红外遥控系统原理及单片机解码实例

红外线遥控是目前使用最广泛的一种通信和遥控手段。由于红外线遥控装置具有体积小、功耗低、功能强、成本低等特点,因而,继彩电、录像机之后,在录音机、音响设备、空凋机以及玩具等其它小型电器装置上也纷纷采用红外线遥控。工业设备中,在高压、辐射、有毒气体、粉尘等环境下,采用红外线遥控不仅完全可靠而且能有效地隔离电气干扰。

1 红外遥控系统

       通用红外遥控系统由发射和接收两大部分组成。应用编/解码专用集成电路芯片来进行控制操作,如图1所示。发射部分包括键盘矩阵、编码调制、LED红外发送器;接收部分包括光、电转换放大器、解调、解码电路。

点击看大图

图1 红外线遥控系统框图
 
2 遥控发射器及其编码
 
       遥控发射器专用芯片很多,根据编码格式可以分成两大类,这里我们以运用比较广泛,解码比较容易的一类来加以说明,现以日本NEC的uPD6121G组成发射电路为例说明编码原理(一般家庭用的DVD、VCD、音响都使用这种编码方式)。当发射器按键按下后,即有遥控码发出,所按的键不同遥控编码也不同。这种遥控码具有以下特征:
 
       采用脉宽调制的串行码,以脉宽为0.56ms、间隔0.565ms、周期为1.125ms的组合表示二进制的“0”;以脉宽为0.56ms、间隔1.685ms、周期为2.25ms的组合表示二进制的“1”,其波形如图2所示。
 
点击看大图
 
图2 遥控码的“0”和“1” (注:所有波形为接收端的与发射相反)

       上述“0”和“1”组成的32位二进制码经38kHz的载频进行二次调制以提高发射效率,达到降低电源功耗的目的。然后再通过红外发射二极管产生红外线向空间发射,如图3所示。

点击看大图

图3 遥控信号编码波形图
 
  UPD6121G产生的遥控编码是连续的32位二进制码组,其中前16位为用户识别码,能区别不同的电器设备,防止不同机种遥控码互相干扰。该芯片的用户识别码固定为十六进制01H;后16位为8位操作码(功能码)及其反码。UPD6121G最多额128种不同组合的编码。

       遥控器在按键按下后,周期性地发出同一种32位二进制码,周期约为108ms。一组码本身的持续时间随它包含的二进制“0”和“1”的个数不同而不同,大约在45~63ms之间,图4为发射波形图。

点击看大图

图4 遥控连发信号波形
 
       当一个键按下超过36ms,振荡器使芯片激活,将发射一组108ms的编码脉冲,这108ms发射代码由一个引导码(9ms),一个结果码(4.5ms),低8位地址码(9ms~18ms),高8位地址码(9ms~18ms),8位数据码(9ms~18ms)和这8位数据的反码(9ms~18ms)组成。如果键按下超过108ms仍未松开,接下来发射的代码(连发码)将仅由起始码(9ms)和结束码(2.25ms)组成。

图5 引导码                  图6连发码
 
3 遥控信号接收
 
       接收电路可以使用一种集红外线接收和放大于一体的一体化红外线接收器,不需要任何外接元件,就能完成从红外线接收到输出与TTL电平信号兼容的所有工作,而体积和普通的塑封三极管大小一样,它适合于各种红外线遥控和红外线数据传输。
       接收器对外只有3个引脚:Out、GND、Vcc与单片机接口非常方便,如图7所示。

   图 7
       ① 脉冲信号输出接,直接接单片机的IO 口。
       ② GND接系统的地线(0V);
       ③ Vcc接系统的电源正极(+5V);
 
4 遥控信号的解码
 
       下面是一个对51实验板配套的红外线遥控器的解码程序,它可以把红外遥控器每一个按键的键值读出来,并且通过实验板上P1口的8个LED显示出来,在解码成功的同时并且能发出“嘀嘀嘀”的提示音。
       ;=================================================
; 红外遥控接收    
;=================================================
;   中山单片机学习网    智佳科技   逸风
;=================================================
ORG 0000H
 
MAIN:
    JNB    P2.2,IR        ;遥控扫描
    LJMP   MAIN           ;在正常无遥控信号时,一体化红外接收头输出是高电平,程序一直在循环。
 
;=================================================
;=================================================
;   解码程序
IR:
    ;以下对遥控信号的9000微秒的初始低电平信号的识别,波形见图5。
    MOV    R6,#10
IR_SB:
    ACALL DELAY882        ;调用882微秒延时子程序
    JB     P2.2,IR_ERROR  ;延时882微秒后判断P2.2脚是否出现高电平如果有就退出解码程序
    DJNZ   R6,IR_SB       ;重复10次,目的是检测在8820微秒内如果出现高电平就退出解码程序
 
    ;识别连发码,和跳过4.5ma的高电平。
    JNB     P2.2, $       ;等待高电平避开9毫秒低电平引导脉冲
    ACALL  DELAY2400
    JNB     P2.2,IR_Rp    ;这里为低电平,认为是连发码信号,见图6。
    ACALL  DELAY2400      ;延时4.74毫秒避开4.5毫秒的结果码
 
    ;以下32数据码的读取 ,0和1的识别 请看图2
    MOV     R1,#1AH        ;设定1AH为起始RAM区
    MOV     R2,#4
IR_4BYTE:
    MOV     R3,#8
IR_8BIT:  
    JNB     P2.2,$         ;等待地址码第一位的高电平信号
    LCALL  DELAY882        ;高电平开始后用882微秒的时间尺去判断信号此时的高低电平状态
    MOV    C,P2.2          ;将P2.2引脚此时的电平状态0或1存入C中
    JNC     IR_8BIT_0      ;如果为0就跳转到IR_8BIT_0
    LCALL  DELAY1000
IR_8BIT_0:
    MOV    A,@R1           ;将R1中地址的给A
    RRC    A               ;将C中的值0或1移入A中的最低位
    MOV    @R1,A           ;将A中的数暂时存放在R1中
    DJNZ   R3,IR_8BIT      ;接收地址码的高8位
    INC    R1              ;对R1中的值加1,换下一个RAM
    DJNZ   R2,IR_4BYTE     ;接收完16位地址码和8位数据码和8位数据,
                           ;存放在1AH/1BH/1CH/1DH的RAM中
 
    ;解码成功
    JMP    IR_GOTO
IR_Rp:
    ;这里为重复码执行处
    ;按住遥控按键时,每过108ms就到这里来
    JMP    IR_GOTO
 
IR_ERROR:
    ;错语退出
    LJMP   MAIN ;退出解码子程序
 
;遥控执行部份
IR_GOTO:
    ;这里还要判断1AH和1BH 两个系统码或用户码,用于识别不同的遥控器
    ;MOV   A,1AH
    ;CJNE  A,#xxH,IR_ERROR   ;用户码1不对则退出
    ;MOV   A,1BH
    ;CJNE  A,#xxH,IR_ERROR   ;用户码2不对则退出
 
    ;判断两个数据码是否相反
    MOV    A,1CH
    CPL    A
    CJNE   A,1DH,IR_ERROR    ;两个数据码不相反则退出
 
    ;遥控执行部份
    ;MOV   A,1DH             ;判断对应按键
    ;CJNE  A,#xxH,$+6
    ;LJMP  -à跳到对应按键执行处
    ;CJNE  A,#xxH,$+6
    ;LJMP  -à跳到对应按键执行处
 
    MOV     P1,1DH         ;将按键的键值通过P1口的8个LED显示出来!
    CLR     P2.3          ;蜂鸣器鸣响-嘀嘀嘀-的声音,表示解码成功
    LCALL  DELAY2400
    LCALL  DELAY2400
    LCALL  DELAY2400
    SETB   P2.3          ;蜂鸣器停止
 
    ;清除遥控值使连按失效
    MOV    1AH,#00H
    MOV    1BH,#00H
    MOV    1CH,#00H
    MOV    1DH,#00H
    LJMP   MAIN
 
;=================================================
; 延时子程序
;=============================882
DELAY882: ;1.085x ((202x4)+5)=882
    MOV R7,#202
DELAY882_A:
    NOP
    NOP
    DJNZ   R7,DELAY882_A
RET
 
;=============================1000
DELAY1000: ;1.085x ((229x4)+5)=999.285
    MOV R7,#229
DELAY1000_A:
    NOP
    NOP
    DJNZ   R7,DELAY1000_A
RET
;=============================2400
DELAY2400: ;1.085x ((245x9)+5)=2397.85
    MOV R7,#245
DELAY2400_A:
    NOP
    NOP
    NOP
    NOP
    NOP
   NOP
    NOP
    DJNZ   R7,DELAY2400_A
RET
END
系统分类: 单片机
用户分类: 嵌入式系统开发
标签: 红外遥控 红外编码 红外解码
来源: 转贴
发表评论 阅读全文(1115) | 回复(0)

0

关于投票
PIC18Fxx8之CAN信息接收过滤器与屏蔽器

1_00A:信息接收过滤器与屏蔽器

信息接收过滤器与屏蔽器用于确定信息缓冲器MAB中的信息是否被装入其中一个接收缓冲器。一旦一条有效的信息被MAB接收,信息的标识符区域将与过滤器值进行比较,如果相匹配,那么信息将被装入相应的接收缓冲器。过滤器屏蔽器用于确定标识符中的哪一位被过滤器检查。表19.2 介绍了标识符中的每一位如何与屏蔽器和过滤器进行比较来确定信息是否应该被装入接收缓冲器。屏蔽位通常是来确定哪一位是用于用于接收过滤器。如果任一屏蔽位配置为0,那么此位将自动接收,而不考虑过滤器位的状态。

*************************************************************

The Message Acceptance Filters and Masks are used to determine if a message in the message assembly buffer should be loaded into either of the receive buffers.  Once a valid message has been received into the MAB, the identifier fields of the message are compared to the filter values. If there is a match, that message will be loaded into the appropriate receive buffer. The filter masks are used to determine which bits in the identifier are examined with the filters. A truth table is shown below in Table 19-2, that indicates how each bit in the identifier is compared to the masks and filters to determine if a message should be loaded into a receive buffer. The mask essentially determines which bits to apply the acceptance filters to. If any mask bit is set to a zero, then that bit will automatically be accepted, regardless of the filter bit.

系统分类: 嵌入式
用户分类: 嵌入式系统开发
标签: PIC18Fxx8 CAN 过滤器与屏蔽器
来源: 整理
发表评论 阅读全文(420) | 回复(0)

0

关于投票
PIC18Fxx8之CAN时间标记

1_00d:时间标记

CAN 模块可以编程为每一条接收到的信息生成一个时间标记。当使能时,模块用CCP1产生一个捕捉信号,该信号轮流捕捉定时器TMR1或TMR3的值。该值可以用作信息的时间标记。

要使用时间标记功能,必须将CANCAP(CIOCAN<4>)置1。这样就可以用CAN模块产生的信号取代CCP1捕捉的输入信号。另外,必须将 CCP1CON<3:0> 配置为0011,从而使能CCP特殊事件触发器捕捉CAN事件。

---------------------------------------------------------------------------------------------

The CAN module can be programmed to generate a time-stamp for every message that is received. When enabled, the module generates a capture signal for CCP1, which in turns captures the value of either Timer1 or Timer3. This value can be used as the message time-stamp.

To use the time-stamp capability, the CANCAP bit (CIOCAN<4>) must be set. This replaces the capture input for CCP1 with the signal generated from the CAN module. In addition, CCP1CON<3:0> must be set to‘0011’ to enable the CCP special event trigger for CAN
events.

系统分类: 嵌入式
用户分类: 嵌入式系统开发
标签: PIC18Fxx8 CAN 时间标记
来源: 整理
发表评论 阅读全文(375) | 回复(0)

0

关于投票
PIC18Fxx8之CAN接收优先级

1_00c: 接收优先级

RXB0是较高优先级的接收缓冲器,它有两个与之相关的接收过滤器。RXB1为较低优先级的接收缓冲器,它有四个与之相关的接收过滤器。较低序号的接收过滤器与RXB0匹配更受严格的限制,对接收缓冲器而言意味着更高的优先级。另外,RXB0CON寄存器能够配置为如果RXB0包含了一条有效信息,而另一条有效信息又被接收时,新的信息将被移入RXB1中,而不考虑RXB1的接收标准,溢出错误不会发生。同样,接收缓冲器都有一个可编程的接收过滤器和屏蔽器。

当接收信息时,RXBnCON<3:0>指示了接收过滤器的序号来确定哪个过滤器使能接收,而不管接收的信息是否为远程传输请求。

RXM位用来配置特殊的接收方式。一般地,这两位置为00来接收所有有效的信息,由相应的接收过滤器决定。这样,是否接收标准或扩展信息是由是由接收过滤器寄存器中的EXIDE位决定。如果RXM位配置成01或10,接收器只接收标准或扩展表识符的信息。如果接收过滤器寄存器中的EXIDE位为1,就不会对RXM相应,接收过滤器处于无效状态。RXM位用于总线上只有标准或扩展表识符信息的系统。如果RXM位配置为11,缓冲器将接收所有信息,而不考虑接收过滤器的值。同样,如果信息在结束帧前有错误,则在结束帧前有错误,则在错误帧前面的MAB中的那部分信息将装入缓冲器。

********************************************************************

RXB0 is the higher priority buffer and has two message acceptance filters associated with it. RXB1 is the lower priority buffer and has four acceptance filters associated with it. The lower number of acceptance filters makes the match on RXB0 more restrictive and implies a higher priority for that buffer. Additionally, the RXB0CON register can be configured such that if
RXB0 contains a valid message and another valid message is received, an overflow error will not occur and the new message will be moved into RXB1, regardless of the acceptance criteria of RXB1. There are also two programmable acceptance filter masks available, one for each receive buffer .

When a message is received, bits <3:0> of the RXBnCON register will indicate the acceptance filter number that enabled reception and whether the received message is a remote transfer request.

The RXM bits set special Receive modes. Normally, these bits are set to ‘00’ to enable reception of all valid messages, as determined by the appropriate acceptance filters. In this case, the determination of whether or not to receive standard or extended messages is determined by the EXIDE bit in the acceptance filter register. If the RXM bits are set to ‘01’ or ‘10’, the receiver will accept only messages with standard or extended identifiers, respectively. If an acceptance filter has the EXIDE bit set, such that it does not correspond with the RXM mode, that acceptance filter is rendered useless. These two modes of RXM bits can be used in systems where it is known that only standard or extended messages will be on the bus. If the RXM bits are set to ‘11’, the buffer will receive all messages, regardless of the values of the acceptance filters. Also, if a message has an error before the end of frame, that portion of the message assembled in the MAB before the error frame, will be loaded into the buffer. This mode has some value in debugging a CAN system and would not be used in an actual system environment.

<