本帖最后由 tyw 于 2022-6-9 14:06 编辑
- /* =========================================================================
- ; File: main.asm (NY8A053E LVD function can't emulate in NY8_ICE. This function must be verification in real chip. )
- ; Description: This Project teaches how to set LVD
- ; 1. FINST = 4MHz/4T(I_HRC)
- ; 2. Set LVD vlotage is 2.8V,
- ; PB0 polling with SFR bit "LVDOUT" at PCON1[6]. When VDD voltage below LVD voltage, then PB0 output low.
- ;
- ; 2.1 Using Power noise bypass capacitor between VDD and GND (0.1uF)
- ; 2.2 Set CMPCR[3:0] : 1010
- ; 2.3 LVDS[3:0] 0000 => 1.9V
- ; 0001 => 2.0V
- ; 0010 => 2.2V
- ; 0011 => 2.4V
- ; 0100 => 2.6V
- ; 0101 => 2.8V
- ; 0110 => 2.9V
- ; 0111 => 3.0V
- ; 1000 => 3.15V
- ; 1001 => 3.3V
- ; 1010 => 3.45V
- ; 1011 => 3.6V
- ; 1100 => 3.75V
- ; 1101 => 3.9V
- ; 1110 => 4.05V
- ; 1111 => 4.15V
- ;
- ; Author: JasonLee
- ; Version: V1.0
- ; Date: 2020/08/05
- =========================================================================*/
- #include <ny8.h>
- #include "ny8_constant.h"
- void main(void)
- {
- // Initial GPIO
- PORTB = 0; // PortB outputs Low
- IOSTB = 0x3E; // PB0 sets as output mode, others are input mode
- DISI(); // Disable all unmasked interrupts
- INTE = 0; // Disabl Interrupt Enable Register
- CMPCR = C_RBias_High_Dis | C_RBias_Low_Dis| C_CMPFINV_Dis | 0x0A; // initial SFR CMPCR (CMPF_INV=0) measure LVD_L
- PCON1 = C_LVD_2P8V; // Set LVDS[3:0]=0101b (2.8V) , Timer0 disable
- PCONbits.LVDEN = 1; // Enable low-voltage detector
- while(1)
- {
- if(PCON1 & 0x40)
- PORTBbits.PB0 = 1; // LVDOUT -> PB0
- else
- PORTBbits.PB0 = 0; // LVDOUT -> PB0
- CLRWDT(); // Clear WatchDog
- }
- }
/* =========================================================================
; File: main.asm (NY8A053E LVD function can't emulate in NY8_ICE. This function must be verification in real chip. )
; Description: This Project teaches how to set LVD
; 1. FINST = 4MHz/4T(I_HRC)
; 2. Set LVD vlotage is 2.8V,
; PB0 polling with SFR bit "LVDOUT" at PCON1[6]. When VDD voltage below LVD voltage, then PB0 output low.
;
; 2.1 Using Power noise bypass capacitor between VDD and GND (0.1uF)
; 2.2 Set CMPCR[3:0] : 1010
; 2.3 LVDS[3:0] 0000 => 1.9V
; 0001 => 2.0V
; 0010 => 2.2V
; 0011 => 2.4V
; 0100 => 2.6V
; 0101 => 2.8V
; 0110 => 2.9V
; 0111 => 3.0V
; 1000 => 3.15V
; 1001 => 3.3V
; 1010 => 3.45V
; 1011 => 3.6V
; 1100 => 3.75V
; 1101 => 3.9V
; 1110 => 4.05V
; 1111 => 4.15V
;
; Author: JasonLee
; Version: V1.0
; Date: 2020/08/05
=========================================================================*/
#include <ny8.h>
#include "ny8_constant.h"
void main(void)
{
// Initial GPIO
PORTB = 0; // PortB outputs Low
IOSTB = 0x3E; // PB0 sets as output mode, others are input mode
DISI(); // Disable all unmasked interrupts
INTE = 0; // Disabl Interrupt Enable Register
CMPCR = C_RBias_High_Dis | C_RBias_Low_Dis| C_CMPFINV_Dis | 0x0A; // initial SFR CMPCR (CMPF_INV=0) measure LVD_L
PCON1 = C_LVD_2P8V; // Set LVDS[3:0]=0101b (2.8V) , Timer0 disable
PCONbits.LVDEN = 1; // Enable low-voltage detector
while(1)
{
if(PCON1 & 0x40)
PORTBbits.PB0 = 1; // LVDOUT -> PB0
else
PORTBbits.PB0 = 0; // LVDOUT -> PB0
CLRWDT(); // Clear WatchDog
}
}
芯片:NY8A053E
|