SH79F642B V2.0
SH79F642B V2.0
Single-phase Energy Metering IC integrated LCD driver and enhanced 8051 Microcontroller
1. Features
8051 compatible Pipe-lined instruction based on the 5 channels 10-bit Analog to Digital Converter
single-chip 8-bit micro-controller (ADC) with built-in compare function
Flash ROM: 64K Bytes EUART0,EUART1 (built-in IR), EUART2
EEPROM: 2K Bytes Built-in Calendar clock
RAM: internal 256 Bytes and external 2816 Bytes Two 12-bit PWM timers
LCD RAM:32 Bytes LCD driver:
Operation voltage: 2.2V - 3.8V - 4 COM x 32 SEG (1/4 duty 1/3 bias)
Oscillator (Code option): - 6 COM x 30 SEG (1/6 duty 1/3 bias)
- fOSC=32.768kHz - 8 COM x 28 SEG (1/8 duty 1/4 bias)
- Build in PLL : PLL= 8.192MHz - 8 levels contrast software programmable
46 CMOS general purpose I/O ports Built-in low power detection (LPD)
Built-in pull-up resistor for I/O Built-in low voltage reset (LVR) function (enabled
Three 16-bit timer / counters: T0, T1 & T2 by code option)
Powerful interrupt sources: LVR voltage: 2.3V
- Timer0, Timer1, Timer2 Built-in Watch Dog Timer (WDT)
- External interrupt 1, 2, 3 Warm-up timer for power-on reset
- EUART0, EUART1, EUART2 CPU Machine cycle: 1 oscillator clock
- RTC, LPD Support Low power operation modes:
- ADC, EMU, PWM - IDLE Mode
Energy Metering - Power-Down Mode
Active/ reactive/ apparent Energy Metering and voltage/ Low-power Comsumption
current rms metering Package: LQFP64(10*10) / LQFP64 (7*7)
Accuracy of 0.1% for active energy over a dynamic
range of 2000:1.
Accuracy of 0.5% for reactive energy over a dynamic
range of 1000:1.
Less than 0.5% error for voltage/ current rms
2. General Description
The SH79F642B is a low-cost,high-performance single-phase energy metering SOC chip, and integrated single-phase
energy metering, LCD driver, Calendar clock and enhanced 8051 microcontroller.
SH79F642B embedded energy metering module, to measure active, reactive and apparent energy, as well as voltage/
current rms. And then to monitor the voltage sag of the power line and zero-crossing features.
The SH79F642B is a fast 8051 compatible micro-controller with a redesigned CPU of no wasted clock and memory cycles.
Typically, it will be faster and exhibit better performance than the traditional 8051 at the same oscillator frequency.
The SH79F642B retains most features of the standard 8051. These features include internal 256 bytes RAM, two 16-bit
timers / counters, three UART, and external interrupt INT1. In addition, the SH79F642B provides external 2816 bytes RAM (not
include LCD RAM), two 12-bit PWM outputs, external interrupt INT2&3, 16-bit timer/counter (Timer2) compatible with 8052. It
contains a 64K Bytes Flash memory block for program and data.
Some standard serial communication modes such as EUART、IR are supported in SH79F642B. Also the LCD driver,
ADC,PWM Timer and RTC are incorporated in SH79F642B.
For high reliability and low cost issues, the SH79F642B builds in PLL clock, LCD Driver, Watchdog Timer, Low Voltage
Reset function, and oscillator fail detection. SH79F642B also supports two power supply modes and two power saving modes
to reduce power consumption.
1 V2.0
SH79F642B
3. Block Diagram
VDD
VBAT Reset circuit RST
Pipelined 8051 architecture
Power Watch Dog
VOUT
T0 Port 5 Configuration
Timer0 (16bit) P5.0 ~ P5.7
T1 I/Os
Timer1 (16bit)
T2
Timer2 (16bit)
T2EX Port 4 Configuration
P4.0 ~ P4.7
I/Os
INT0
INT1 Port 3 Configuration
INT2 External Interrupt P3.0~P3.6
I/Os
INT3
Port 2 Configuration
AN0 P2.0 ~ P2.7
I/Os
AN1
AN2 ADC
Port 1 Configuration
AN3 P1.0 ~ P1.7
I/Os
AN5
PWM0 Port 0 Configuration
PWM P0.0 ~ P0.7
PWM1 I/Os
Regulator C
AVCC LDO
2
SH79F642B
4. Pin Configuration
P1.4//PWM0/SEG1//COM5
P0.6/SEG11/RXD2
P0.7/SEG12/TXD2
P1.5/SEG2/COM6
P1.7/SEG4/COM8
P1.6/SEG3/COM7
P0.5/SEG10/TCK
P0.3/SEG8/TMS
P0.2/SEG7/TDO
P0.4/SEG9/TDI
P1.3/COM4
P1.2/COM3
P1.1/COM2
P1.0/COM1
P0.0/SEG5
P0.1/SEG6
48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33
SEG13/P4.0 49 32 P3.6/SEG32/TXD0
SEG14/P4.1 50 31 P3.5/SEG31/RXD0
SEG15/P4.2 51 30 P3.4/SEG30/TXD1/IOMUX
SEG16/P4.3 52 29 P3.3/SEG29/RXD1
SEG17/P4.4 53 28 P3.2/T2/CALOUT
SEG18/P4.5 54 27 P3.0/T2EX/T0
SEG19/P4.6 55 26 P2.7/INT2/T1/AN5
SEG20/P4.7 56 SH79F642B 25 P2.6/INT3/AN3
(LQFP64)
SEG21/P5.0 57 24 P2.5/QF/AN2
SEG22/P5.1 58 23 P2.4/PF/CALOUT2/AN1
SEG23/P5.2 59 22 P2.3/AN0/VIN
SEG24/P5.3 60 21 P2.2
SEG25/P5.4 61 20 P2.1
SEG26/P5.5 62 19 P2.0/RST
SEG27/PWM1/P5.6 63 18 NC
SEG28/INT1/P5.7 64 17 XTAL1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
VDD
NC
DGND
AVCC
VBAT
VOUT
I2P
I1P
I2N
XTAL2
I1N
AGND
VREF
VN
VP
Note: The out most pin function has the highest priority, and the inner most pin function has the lowest priority (Refer to Pin
Configuration Diagram). This means when one pin is occupied by a higher priority function (if enabled) cannot be used as the
lower priority functional pin, even when the lower priority function is also enabled. Only until the higher priority function is
disabled by software, can the corresponding pin be released for the lower priority function use.
3
SH79F642B
Table 4.1 Pin Functions
Pin No. Pin Name Default function Pin No. Pin Name Default function
1 NC ------ 33 COM1/P1.0 P1.0
2 VREF ------ 34 COM2/P1.1 P1.1
3 VP ------ 35 COM3/P1.2 P1.2
4 VN ------ 36 COM4/P1.3 P1.3
COM5/SEG1/
5 I2P ------ 37 P1.4
PWM0/P1.4
6 I2N ------ 38 COM6/SEG2/ P1.5 P1.5
7 I1N ------ 39 COM7/SEG3/ P1.6 P1.6
8 I1P ------ 40 COM8/SEG4/ P1.7 P1.7
9 AGND ------ 41 SEG5/P0.0 P0.0
10 DGND ------ 42 SEG6/P0.1 P0.1
11 AVCC ------ 43 TDO/SEG7/P0.2 P0.2
12 VBAT ------ 44 TMS/SEG8/P0.3 P0.3
13 VDD ------ 45 TDI/SEG9/P0.4 P0.4
14 VOUT ------ 46 TCK/SEG10/P0.5 P0.5
15 C ------ 47 RXD2/SEG11/P0.6 P0.6
16 XTAL2 ------ 48 TXD2/SEG12/P0.7 P0.7
17 XTAL1 ------ 49 SEG13/P4.0 P4.0
18 NC ------ 50 SEG14/P4.1 P4.1
———— ————
19 P2.0/RST RST 51 SEG15/P4.2 P4.2
20 P2.1 P2.1 52 SEG16/P4.3 P4.3
21 P2.2 P2.2 53 SEG17/P4.4 P4.4
22 VIN/AN0/P2.3 VIN 54 SEG18/P4.5 P4.5
23 AN1/CALOUT2/PF/P2.4 P2.4 55 SEG19/P4.6 P4.6
24 AN2/QF/P2.5 P2.5 56 SEG20/P4.7 P4.7
25 AN3/INT3/P2.6 P2.6 57 SEG21/P5.0 P5.0
26 AN5/T1/INT2/P2.7 P2.7 58 SEG22/P5.1 P5.1
27 T0/T2EX/P3.0 P3.0 59 SEG23/P5.2 P5.2
28 CALOUT/T2/P3.2 P3.2 60 SEG24/P5.3 P5.3
29 RXD1/SEG29/P3.3 P3.3 61 SEG25/P5.4 P5.4
30 IOMUX/TXD1/SEG30/P3.4 P3.4 62 SEG26/P5.5 P5.5
31 RXD0/SEG31/P3.5 P3.5 63 SEG27/PWM1/P5.6 P5.6
32 TXD0/SEG32/P3.6 P3.6 64 SEG28/INT1/P5.7 P5.7
4
SH79F642B
5. Pin Description
5
SH79F642B
(Continued)
Pin Name Type Description
Interrupt & Reset & Clock & Power
INT1 - INT3 I External interrupt 1~3
———— A low on this pin for 10us longer will reset the device. An internal diffused 30kohm resistor
RST I
to VDD permits a power-on reset using only an external capacitor to GND.
XTAL1 I Oscillator input
XTAL2 O Oscillator output
DGND P Digital ground
VDD P Power
AGND P Analog ground
Digital power supply circuit,the external need to connect the 4.7uF capacitor to ground,the
C P
typical voltage 1.8V
VOUT P Power output pin(output VDD or VBAT by using a switch ), digital circuit supply.
VBAT P Battery supply
Energy Metering Analog Power with built-in 2.8V LDO output. It requires an 1uF external
AVCC P
ceramic capacitor to GND.
Programmer
TDO (SEG7) O Debug interface: Test data out
TMS (SEG8) I Debug interface: Test mode select
TDI (SEG9) I Debug interface: Test data in
TCK (SEG10) I Debug interface: Test clock in
Note:
When P0.2-0.5 used as debug interface, other functions of P0.2-0.5 are blocked.
External Voltage detection Pin
VIN I External voltage detection input
6
SH79F642B
6. SFR Mapping
The SH79F642B provides 256 bytes of internal RAM to contain general-purpose data memory and Special Function
Register (SFR). The SFR of the SH79F642B fall into the following categories:
Interrupt system registers: IEN0, IEN1, IPH0, IPL0, IPH1, IPL1, EXF0
I/O port registers: P0, P1, P2, P3, P4, P0CR, P1CR, P2CR, P3CR, P4CR, P0PCR, P1PCR, P2PCR,
P3PCR, P4PCR, PXMOD, P5, P5CR, P5PCR,P2DRV,P3DRV
Timer registers: TCON1, TCON, TMOD, TL0, TH0, TL1, TH1, T2CON, T2MOD, EXF0,
TL2, TH2, RCAP2L, RCAP2H
EUART0 registers: PCON, SCON, SBUF, SADDR, SADEN, SBRTH, SBRTL, SFINE
IR registers: IRCON
RTC registers: SBSC, SEC, MIN, HR, DAY, MTH, YR, DOW, RTCDATH, RTCDATL, RTCALM,
A0SEC, A0MIN, A0HR, A0DAY, A0DOW, A1SEC, A1MIN, A1HR, RTCCON,
RTCWR, RTCPSW, RTCIE, RTCIF,RTCTMR
7
SH79F642B
8
SH79F642B
LDOCON DFH 计量LDO电压控制寄存器 ***----- BGEN LDOEN1 LDOEN0 - - - - -
*note: LPDCON value will changed in deferent reset condition .
Table 6.5 Flash control SFRs
POR/WDT/LVR
Mnem Addr Name Reset Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Value
Low byte offset of flash memory for IB_OFF IB_OFF IB_OFF IB_OFF IB_OFF IB_OFF IB_OFF IB_OFF
IB_OFFSET FBH 00000000
programming SET.7 SET.6 SET.5 SET.4 SET.3 SET.2 SET.1 SET.0
Data Register for programming
IB_DATA FCH 00000000 IB_DATA.7 IB_DATA.6 IB_DATA.5 IB_DATA.4 IB_DATA.3 IB_DATA.2 IB_DATA.1 IB_DATA.0
flash memory
IB_CON1 F2H Flash Memory Control Register 1 00000000 IB_CON1.7 IB_CON1.6 IB_CON1.5 IB_CON1.4 IB_CON1.3 IB_CON1.2 IB_CON1.1 IB_CON1.0
IB_CON2 F3H Flash Memory Control Register 2 ----0000 - - - - IB_CON2.3 IB_CON2.2 IB_CON2.1 IB_CON2.0
IB_CON3 F4H Flash Memory Control Register 3 ----0000 - - - - IB_CON3.3 IB_CON3.2 IB_CON3.1 IB_CON3.0
IB_CON4 F5H Flash Memory Control Register 4 ----0000 - - - - IB_CON4.3 IB_CON4.2 IB_CON4.1 IB_CON4.0
IB_CON5 F6H Flash Memory Control Register 5 ----0000 - - - - IB_CON5.3 IB_CON5.2 IB_CON5.1 IB_CON5.0
9
SH79F642B
Table 6.9 Interrupt SFRs
POR/WDT/LVR
Mnem Addr Name Reset Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Value
IEN0 A8H Interrupt Enable Control 0 0000000- EA EADTP ET2 ES0 ET1 EX1 ET0 -
IEN1 A9H Interrupt Enable Control 1 00000000 ELPD ES2 EPWM ES1 ERTC EX3 EX2 EEMU
IPL0 B8H Interrupt Priority Control Low 0 -000000- - PADTPL PT2L PS0L PT1L PX1L PT0L -
IPH0 B4H Interrupt Priority Control High 0 -000000- - PADTPH PT2H PS0H PT1H PX1H PT0H -
IPL1 B9H Interrupt Priority Control Low 1 00000000 PLPDL PES2L PPWML PS1L PRTCL PX3L PX2L PEMUL
IPH1 B5H Interrupt Priority Control High 1 00000000 PLPDH PES2H PPWMH PS1H PRTCH PX3H PX2H PEMUH
10
SH79F642B
P3DRV FAH Drive ability for P3 select 00000000 P3DRV.7 P3DRV.6 P3DRV.5 P3DRV.4 P3DRV.3 P3DRV.2 P3DRV.1 P3DRV.0
11
SH79F642B
Table 6.13 EUART1 SFRs
POR/WDT/LVR
Mnem Addr Name Reset Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Value
PCON 87H Power & serial Control 00000000 SMOD SSTAT SSTAT1 SSTAT2 GF1 GF0 PD IDL
SCON1 D8H Serial Control 00000000 SM10/FE1 SM11/RXOV SM12/TXCO REN1 TB81 RB81 TI1 RI1
1 L1
SBUF1 D9H Serial Data Buffer 00000000 SBUF1.7 SBUF1.6 SBUF1.5 SBUF1.4 SBUF1.3 SBUF1.2 SBUF1.1 SBUF1.0
SADDR1 DAH Slave Address 00000000 SADDR1.7 SADDR1.6 SADDR1.5 SADDR1.4 SADDR1.3 SADDR1.2 SADDR1.1 SADDR1.0
SADEN1 DBH Slave Address Mask 00000000 SADEN1.7 SADEN1.6 SADEN1.5 SADEN1.4 SADEN1.3 SADEN1.2 SADEN1.1 SADEN1.0
SBRTH1 DCH Baud rate high byte 00000000 SBRTEN1 SBRT1.14 SBRT1.13 SBRT1.12 SBRT1.11 SBRT1.10 SBRT1.9 SBRT1.8
SBRTL1 DDH Baud rate low byte 00000000 SBRT1.7 SBRT1.6 SBRT1.5 SBRT1.4 SBRT1.3 SBRT1.2 SBRT1.1 SBRT1.0
SFINE 9EH Baud rate fine tuning for EUART0\1 00000000 SFINE1.3 SFINE1.2 SFINE1.1 SFINE1.0 SFINE.3 SFINE.2 SFINE.1 SFINE.0
12
SH79F642B
Table 6.16 ADC SFRs
POR/WDT/LVR
Mnem Addr Name Reset Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Value
----------------
ADCON C1H ADC control 00000000 ADON ADCIF EC EADC SCH2 SCH1 SCH0 GO/DON E
ADT C2H ADC clock control 000-0000 TADC2 TADC1 TADC0 - TS3 TS2 TS1 TS0
ADCH AFH ADC channel control --0-0000 - - CH5 - CH3 CH2 CH1 CH0
ADDL 91H ADC data low byte ------00 - - - - - - A1 A0
ADDH 92H ADC data high byte 00000000 A9 A8 A7 A6 A5 A4 A3 A2
LCDCON A3H LCD control 0-000000 LCDON - DUTY1 DUTY0 BIAS CONTR2 CONTR1 CONTR0
P0SS AAH P0 or Segment Select 00000000 P0S7 P0S6 P0S5 P0S4 P0S3 P0S2 P0S1 P0S0
P1SS ABH P1 or Segment Select 0000---0 P1S7 P1S6 P1S5 P1S4 - - - COMS
P3SS ACH P3 or Segment Select -0000--- - P3S6 P3S5 P3S4 P3S3 - - -
P4SS ADH P4 or Segment Select 00000000 P4S7 P4S6 P4S5 P4S4 P4S3 P4S2 P4S1 P4S0
P5SS AEH P5 or Segment Select 00000000 P5S7 P5S6 P5S5 P5S4 P5S3 P5S2 P5S1 P5S0
13
SH79F642B
Table 6.18 RTC SFRs
POR/WDT/LVR
Mnem Addr Name Reset Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Value
SBSC FFA0H Sub second REG ******** SBSC7 SBSC6 SBSC5 SBSC4 SBSC3 SBSC2 SBSC1 SBSC0
SEC FFA1H Second REG -******* - SEC6 SEC5 SEC4 SEC3 SEC2 SEC1 SEC0
MIN FFA2H Minute REG ******** - MIN6 MIN5 MIN4 MIN3 MIN2 MIN1 MIN0
HR FFA3H Hour REG --****** - - HR5 HR4 HR3 HR2 HR1 HR0
DAY FFA4H Date REG --****** - - DAY5 DAY4 DAY3 DAY2 DAY1 DAY0
MTH FFA5H Month REG ---***** - - - MTH4 MTH3 MTH2 MTH1 MTH0
YR FFA6H Year REG ******** YR7 YR6 YR5 YR4 YR3 YR2 YR1 YR0
DOW FFA7H Day REG -----*** - - - - - DOW2 DOW1 DOW0
RTCDATH FFA8H RTC compensation value (E) high -******* - - E13 E12 E11 E10 E9 E8
byte
RTC compensation value (E) low
RTCDATL FFA9H ******** E7 E6 E5 E4 E3 E2 E1 E0
byte
RTCALM FFAAH RTC alarmer control ******** ALM1C2 ALM1C1 ALM1C0 ALM0C4 ALM0C3 ALM0C2 ALM0C1 ALM0C0
A0SEC FFABH Alarmer0 Second REG -******* - A0SEC6 A0SEC5 A0SEC4 A0SEC3 A0SEC2 A0SEC1 A0SEC0
A0MIN FFACH Alarmer0 Minute REG -******* - A0MIN6 A0MIN5 A0MIN4 A0MIN3 A0MIN2 A0MIN1 A0MIN0
A0HR FFADH Alarmer0 Hour REG --****** - - A0HR5 A0HR4 A0HR3 A0HR2 A0HR1 A0HR0
A0DAY FFAEH Alarmer0 Date REG --****** - - A0DAY5 A0DAY4 A0DAY3 A0DAY2 A0DAY1 A0DAY0
A0DOW FFAFH Alarmer0 Day REG -----*** - - - - - A0DOW2 A0DOW1 A0DOW0
A1SEC FFB0H Alarmer1 Second REG -******* - A1SEC6 A1SEC5 A1SEC4 A1SEC3 A1SEC2 A1SEC1 A1SEC0
A1MIN FFB1H Alarmer1 Minute REG -******* - A1MIN6 A1MIN5 A1MIN4 A1MIN3 A1MIN2 A1MIN1 A1MIN0
A1HR FFB2H Alarmer1 Hour REG --****** - - A1HR5 A1HR4 A1HR3 A1HR2 A1HR1 A1HR0
RTCCON FFB3H RTC control 0***0*** RTCRD ITEN ITS1 ITS0 OUTEN OUTS OUTF1 OUTF0
RTCWR FFB4H Writtern protect for RTC 00000000 RTCWR7 RTCWR6 RTCWR5 RTCWR4 RTCWR3 RTCWR2 RTCWR1 RTCWR0
RTCPSW FFB5H Writtern protect security code for 00000000 PSW7 PSW6 PSW5 PSW4 PSW3 PSW2 PSW1 PSW0
RTC
RTCIE FFB6H RTC interrupt control 0000000- IT0IE DAYIE HRIE MINIE SECIE ALM1IE ALM0IE -
RTCIF FFB7H RTC interrupt flag *******- IT0IF DAYIF HRIF MINIF SECIF ALM1IF ALM0IF -
RTCECL FFB8H RTC bias at room temperature low uuuuuuuu EC7 EC6 EC5 EC4 EC3 EC2 EC1 EC0
byte
RTC bias at room temperature high
RTCECH FFB9H uuuuuuuu EC15 EC14 EC13 EC12 EC11 EC10 EC9 EC8
byte
14
SH79F642B
RTCTMR FFBAH RTC Timer uuuuuuuu RTCT7 RTCT6 RTCT5 RTCT4 RTCT3 RTCT2 RTCT1 RTCT0
Note: u:Reset does not affect the current value;*:Power on reset value is random number, and other forms of reset is u.
Table 6.19 EMU SFRs
POR/WDT/LVR
Mnem Addr Name Reset Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Value
EADR D1H EMU Address Register 00000000 RW EADR.6 EADR.5 EADR.4 EADR.3 EADR.2 EADR.1 EADR.0
EDTAH D2H EMU Data Register high byte 00000000 EDTAH.7 EDTAH.6 EDTAH.5 EDTAH.4 EDTAH.3 EDTAH.2 EDTAH.1 EDTAH.0
EDTAM D3H EMU Data Register mid byte 00000000 EDTAM.7 EDTAM.6 EDTAM.5 EDTAM.4 EDTAM.3 EDTAM.2 EDTAM.1 EDTAM.0
EDTAL D4H EMU Data Register low byte 00000000 EDTAL.7 EDTAL.6 EDTAL.5 EDTAL.4 EDTAL.3 EDTAL.2 EDTAL.1 EDTAL.0
EMUSR D5H EMU Status/Control Register ******** DSPEN EMUCLK1 EMUCLK0 SAGF NoQLd NoPLd REVQ REVP
EMUIE D6H EMU interrupt enable Register 00000000 QFEN PFEN DSPIE QFIE PFIE SUMIE SAGIE ZXIE
EMUIF D7H EMU interrupt request Register --00000000 - - DSPIF QFIF PFIF SUMIF SAGIF ZXIF
注意:*:EMUSR initial value will vary according to the different types of reset.
Table 6.20 External Interrupt SFRs
POR/WDT/LVR
Mnem Addr Name Reset Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Value
EXF0 E8H External interrupt 0 flag --000000 - EMUF IT31 IT30 IT21 IT20 IE3 IE2
TCON 88H Timer/Counter 2 Control 00000-- TF1 TR1 TF0 TR0 IE1 IT1 - -
15
SH79F642B
PWM1DH 95H PWM1 duty high 4bit ----0000 - - - - PWM1D.11 PWM1D.10 PWM1D.9 PWM1D.8
PWM1DL 94H PWM1 duty low 8bit 00000000 PWM1D.7 PWM1D.6 PWM1D.5 PWM1D.4 PWM1D.3 PWM1D.2 PWM1D.1 PWM1D.0
16
SH79F642B
Single-phase Energy Metering IC integrated LCD driver and enhanced 8051 Microcontroller
Bit
Non Bit Addressable
Addressable
B8h IPL0 IPL1 SBUF2 SADDR2 SADEN2 SBRT2H SBRT2L LPDCON1 BFh
17 V1.0
SH79F642B
FF98h - - - - - - - - FF9Fh
FF90h - - - - - - FF97h
FF88h - - - - - - - - FF8Fh
FF80h - - - - - - FF87h
0/8 1/9 2/A 3/B 4/C 5/D 6/E 7/F
note: The unused addresses of SFR are not available.
SFR Reset Value
SFR Name Reset Value
ACC 00000000b
B 00000000b
AUXC 00000000b
PSW 00000000b
SP 00000111b
DPL 00000000b
DPH 00000000b
DPL1 00000000b
DPH1 00000000b
INSCON 00000000b
18
SH79F642B
7. Normal Function
7.1 Instruction Extension
7.1.1 CPU Core SFR
Feature
CPU core registers: ACC, B, PSW, SP, DPL, DPH
Accumulator
ACC is the Accumulator register. The mnemonics for accumulator-specific instructions, however, refer to the Accumulator
simply as A.
B Register
The B register is used during multiply and divide operations. For other instructions it can be treated as another scratch pad
register.
Bit
Bit Mnemonic Description
Number
Carry flag bit
7 CY 0: no carry or borrow in an arithmetic or logic operation
1: a carry or borrow in an arithmetic or logic operation
Auxiliary Carry flag bit
6 AC 0: an auxiliary carry or borrow in an arithmetic or logic operation
1: an auxiliary carry or borrow in an arithmetic or logic operation
F0 flag bit
5 F0
Available to the user for general purposes
R0-R7 Register bank select bits
00: Bank 0 (Address to 00H-07H)
4-3 RS[1:0] 01: Bank 1 (Address to 08H-0FH)
10: Bank 2 (Address to 10H-17H)
11: Bank 3 (Address to 18H-1FH)
Overflow flag bit
2 OV 0: no overflow happen
1: an overflow happen
F1 flag bit
1 F1 Available to the user for general purposes
19
SH79F642B
Data Pointer Register (DPTR)
DPTR consists of a high byte (DPH) and a low byte (DPL). Its intended function is to hold a 16-bit address, but it may be
manipulated as a 16-bit register or as two independent 8-bit registers.
The SH79F642B has modified 'MUL' and 'DIV' instructions. These instructions support 16 bit operand. A new register - the
register is applied to hold the upper part of the operand/result.
The AUXC register is used during 16 bit operand multiply and divide operations. For other instructions it can be treated as
another scratch pad register.
After reset, the CPU is in standard mode, which means that the 'MUL' and 'DIV' instructions are operating like the standard
8051 instructions. To enable the 16 bit mode operation, the corresponding enable bit in the INSCON register must be set.
Result
Operation
A B AUXC
INSCON.2 = 0; 8 bit mode (A)*(B) Low Byte High Byte ---
MUL
INSCON.2 = 1; 16 bit mode (AUXC A)* (B) Low Byte Middle Byte High Byte
INSCON.3 = 0; 8 bit mode (A) / (B) Quotient Low Byte Remainder ---
DIV
INSCON.3 = 1; 16 bit mode (AUXC A) / (B) Quotient Low Byte Remainder Quotient High Byte
DPTR1 is the same with DPTR, which consists of a high byte (DPH1) and a low byte (DPL1). Its intended function is to hold a
16-bit address, but it may be manipulated as a 16-bit register or as two independent 8-bit registers.
The DPS bit in INSCON register is used to choose the active pointer. The user can switch data pointers by toggling the DPS bit.
And all DPTR-related instructions will use the currently selected data pointer.
7.1.3 Register
Table 7.2 Data Pointer Select Register
86H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
INSCON - - - - DIV MUL - DPS
R/W - - - - R/W R/W - R/W
Reset Value
- - - - 0 0 - 0
(POR/WDT/LVR/PIN)
20
SH79F642B
7.2 RAM
7.2.1 Features
SH79F642B provides both internal RAM and external RAM for random data storage. The internal data memory is mapped
into four separated segments:
1. The Lower 128 bytes of RAM (addresses 00h to 7Fh) are directly and indirectly addressable.
2. The Upper 128 bytes of RAM (addresses 80h to FFh) are indirectly addressable only.
3. The Special Function Registers (SFR, addresses 80h to FFh) are directly addressable only.
4. The expanded RAM bytes are indirectly accessed by MOVX instructions.
The Upper 128 bytes occupy the same address space as SFR, but they are physically separate from SFR space. When an
instruction accesses an internal location above address 7Fh, the CPU can distinguish whether to access the upper 128 bytes
data RAM or to access SFR by different addressing mode of the instruction.
Note: the unused address is unavailable in SFR.
The SH79F642B provides 256 bytes RAM in internal data space, additional 2816 bytes RAM in external data space for
increasing data handling requirement, high level language support and LCD RAM (B00h – B26h) configuration.
B1FH
LCD RAM
AFFH
The SH79F642B provides traditional method for accessing of external RAM. Use MOVX A, @Ri or MOVX @Ri, A; to
access external low 256 bytes RAM; MOVX A, @DPTR or MOVX @DPTR, A to access external 64K bytes RAM.
In SH79F642B, the user can also use XPAGE register to access external RAM only with MOVXA, @Ri or MOVX @Ri, A
instructions. The user can use XPAGE to represent the high byte address of RAM above 256 Bytes.
In flash SSP mode, the XPAGE can also be used as sector selector (Refer to SSP Function)
21
SH79F642B
7.2.2 Register
Table 7.3 Data memory page Register
F7H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
XPAGE XPAGE.7 XPAGE.6 XPAGE.5 XPAGE.4 XPAGE.3 XPAGE.2 XPAGE.1 XPAGE.0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
22
SH79F642B
7.3 Flash Program Memory
7.3.1 Features
The program memory consists 64 * 1KB sectors, total 64KB
Programming and erase can be done over the full operation voltage range
Support 4 code protection mode
Write, read and erase operation are all supported by In-Circuit Programming (ICP)
Support overall/sector erase and programming
Minimum program/erase cycles: Program block : 10,000
EEPROM-like block : 100,000
Minimum years data retention: 20
Low power consumption
FFFFH
07FFH
EEPROM Like Data Block Program Memory Block
0000H 0000H
Code protection mode 0: encrypt the programmer, allow/forbid any programmer write/read operations (not including overall
erase), the uint is 4K (4 sectors), and can protect them respectively.
Code protection mode 1: encrypt the MOVC instruction, allow/forbid through MOVC instructions to read operation in other
sectors, or through SSP mode to erased/write operation, the uint is 4K (4 sectors), and can protect
them respectively.
Code protection mode 2: SSP function allow/forbid control, when selected, chip’s SSP operation (erase or write, not include
read)for code block is forbid, but not for EEPROM-like.
Code protection mode 3: customer password protection, can set password by customer, the password is 6 bytes. If this function
is enable, it means that entering this password first before the programmer or simulator tool do any
23
SH79F642B
operation (read, write, erase or simulate)for the chip, if the password is right, then the chip allows the
programmer or simulator tool to do the corresponding operation, otherwise it gives error, and don’t
perform the corresponding operation.
The user must use one of the following two ways to complete code protection control mode Settings:
I. Flash programmer in ICP mode is set to corresponding protection bit to enter the protected mode.
II. The SSP mode does not support code protection control mode programming.
(2) Overall Erase
Regardless of the state of the code protection control mode, the overall erase operation will erase all programs, code options,
the code protection bit, but they will not erase EEPROM-like memory block.
The user must use the following way to complete the overall erase:
I. Flash programmer in ICP mode send overall erase instruction to run overall erase.
II. The SSP mode does not support overall erase mode.
(3) Sector Erase
Sector erase operations will erase the content of selected sector. The user program (SSP) and Flash programmer can perform
this operation.
For user programs to perform the operation, code protection mode 1 and mode 2 in the selected sector must be forbidden.
For Flash programmer to perform the operation, code protection mode 0 in the selected sector must be forbidden. If code
protection mode 3 is enable, user must enter the correct password.
The user must use one of the following two ways to complete sector erase:
1. Flash programmer in ICP mode send sector erase instruction to run sector erase.
2. Through the SSP function send sector erase instruction to run sector erase (see chapter SSP).
For user programs to perform the reading operation, code protection mode 1 in the selected sector must be forbidden.
Regardless of the security bit Settings or not, the user program can read/write the sector which contains program itself (the unit
is 1K ).
For Flash programmer to perform the writting operation, code protection mode 1 and mode 2 in the selected sector must be
forbidden.
Note: If only enable code protection control mode 1, the user program can’t write other sectors, but it can write the sector which
contains program itself (the unit is 1K ).
If use the programmer to perform the operation, code protection mode 0 in the selected sector must be forbidden.
The user must use one of the following two ways to complete Write/Read Code:
1. Flash programmer in ICP mode send write or read code instruction to run write or read code.
2. Through the SSP function send write or read code instruction to run write or read code;
Through MOVC instruction to perform write or read code.
24
SH79F642B
Flash Memory Block Operation Summary
Operation ICP SSP
Code Protection support not support
Sector Erase support (no security bit) support (no security bit)
Read/write EEPROM-like
support support
memory block
Flash
Programmer
MCU
VDD
TMS
TCK
TDI
TDO
GND
To Application
Circuit
Jumper
Note:Pin C must connect the 4.7uF capacitor to ground.otherwise the programming will be abnormal.
25
SH79F642B
7.4 SSP Function
The SH79F642B provides SSP (Self Sector Programming) function, each sector can be sector erased or programmed by
the user’s code if the selected sector is not be protected. But once sector has been programmed, it cannot be reprogrammed
before sector erase.
The SH79F642B build in a complex control flow to prevent the code from carelessly modification. If the dedicated
conditions are not met (IB_CON2~5), the SSP will be terminated.
7.4.1 Registers
1)Sector select Register for erase/programming and Offset register for Programming
This register is used to select the block code of the sector to be erased/programmed, and coordinates IB_OFFSET register
to indicate the address offset of the byte to be programmed in sector.
For program memory, one sector is 1024 bytes, register is defined as follows:
Table 7.4 Offset register for programming
F7H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
XPAGE XPAGE.7 XPAGE.6 XPAGE.5 XPAGE.4 XPAGE.3 XPAGE.2 XPAGE.1 XPAGE.0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
7-2 XPAGE[7-2] Sector of the flash memory to be programmed, 000000 means sector 0, and so on
1-0 XPAGE[1-0] High Address of Offset of the flash memory sector to be programmed
EEPROM-like sectors, one sector is 256 bytes, in total 8 sectors, register is defined as follows:
Table 7.6 Sector select Register for erase/programming
F7H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
XPAGE XPAGE.7 XPAGE.6 XPAGE.5 XPAGE.4 XPAGE.3 XPAGE.2 XPAGE.1 XPAGE.0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
26
SH79F642B
001:sector 1
…
111: sector 7
Use “MOVC A, @A+DPTR” or “MOVC A, @A+PC” to access EEPROM-like sectors.
Note: Need to set FAC bit in FLASHCON register.
27
SH79F642B
4)SSP Flow Control Register
Table 7.10 SSP Flow Control Register1
F3H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
IB_CON2 - - - - IB_CON2.3 IB_CON2.2 IB_CON2.1 IB_CON2.0
R/W - - - - R/W R/W R/W R/W
Reset Value
- - - - 0 0 0 0
(POR/WDT/LVR/PIN)
28
SH79F642B
7.4.2 Flash Control Flow
Set IB_OFFSET
Set XPAGE
Set IB_DATA
Set IB_CON1
S0
IB_CON2≠5H
S1
IB_CON3≠AH IB_CON2≠5H
Set IB_CON3 = AH
ELSE
S2 IB_CON3≠AH
Set IB_CON4 = 9H
IB_CON4 ≠9H
Reset
IB_CON1-5 S3
Set IB_CON5 = 6H
S4
IB_CON1 = 6EH
& IB_CON2[3:0] = 5H
& IB_CON3 = AH
& IB_CON4 = 9H
& IB_CON5 = 6H
Programming
29
SH79F642B
7.4.3 SSP Programming Notice
To successfully complete SSP programming, the user’s software must following the steps below:
A. For Code/Data Programming: note: need to close code protection mode 1 and mode 2
1. Disable interrupt;
2. Fill in the XPAGE, IB_OFFSET for the corresponding address;
3. Fill in IB_DATA if programming is wanted;
4. Fill in IB_CON1-5 sequentially;
5. Add 4 nops for more stable operation;
6. Code/Data programming, CPU will be in IDLE mode; Exit IDLE mode automatically after programming;
7. Go to Step 2 if more data are to be programmed;
8. Clear XPAGE; enable interrupt if necessary.
B. For Sector Erase: note: need to close code protection mode 1 and mode 2
1. Disable interrupt;
2. Fill in the XPAGE for the corresponding sector;
3. Fill in IB_CON1-5 sequentially;
4. Add 4 NOPs for more stable operation;
5. Sector Erase, CPU will be in IDLE mode; Exit IDLE mode automatically after programming;
6. Go to step 2 if more sectors are to be erased;
7. Clear XPAGE; enable interrupt if necessary.
D. For EEPROM-Like:
Steps is same as code programming, the differences are:
1. Set FAC bit in FLASHCON register before programming or erase EEPROM-Like;
2. One sector of EEPROM-Like is 256 bytes, not 1024 bytes.
Note: The FAC bit must be cleared after reading readable identification code, otherwise it will effect the instruction execution
of user’s program .
30
SH79F642B
7.5.3 Description
SH79F642B Only support 1 oscillator type: 32.768kHz crystal. The oscillator generates the basic clock pulse that provides
the system clock to supply CPU and on-chip peripherals.
A phase locked loop (PLL) oscillator is built in SH79F642B, which can provide up to 8.192MHz oscillator clock. PLLCON
control register can decide whether PLL oscillator is enabled or disabled.
31
SH79F642B
7.5.4 Registers
Table 7.15 System Clock Control register
B2H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
CLKCON 32K_SPDUP CLKS1 CLKS0 - PLLCON FS2 - -
R/W R/W R/W R/W - R/W R/W - -
Reset Value
1 1 1 - 0 0 - -
(POR/WDT/LVR/PIN)
32
SH79F642B
7.5.5 Oscillator Type
32768Hz crystal&internal PLL :
C1
XTAL1
32.768
kHz
XTAL2
C2
Crystal Oscillator
Recommend Type Manufacturer
Frequency C1 C2
DT 38 (φ3x8) KDS
32.768kHz 5~12.5pF 5~12.5pF Shenzhen DGJB
φ3x8 – 32.768kHz
Electronic Co.,Ltd.
Notes:
(1) Capacitor values are used for design guidance only!
(2) These capacitors were tested with the crystals listed above for basic start-up and operation. They are not optimized.
(3) Be careful for the stray capacitance on PCB board, the user should test the performance of the oscillator over the expected
VDD and the temperature range for the application.
Before selecting crystal/ceramic, the user should consult the crystal/ceramic manufacturer for appropriate value of external
component to get best performance, visit http://www.sinowealth.comfor more recommended manufactures
33
SH79F642B
7.6 I/O Port
7.6.1 Features
7.6.2 Registers
Table 7.16 Port Control Register
E1H- E6H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
P0CR (E1H) P0CR.7 P0CR.6 P0CR.5 P0CR.4 P0CR.3 P0CR.2 P0CR.1 P0CR.0
P1CR (E2H) P1CR.7 P1CR.6 P1CR.5 P1CR.4 P1CR.3 P1CR.2 P1CR.1 P1CR.0
P2CR (E3H) P2CR.7 P2CR.6 P2CR.5 P2CR.4 P2CR.3 P2CR.2 P2CR.1 P2CR.0
P3CR (E4H) - P3CR.6 P3CR.5 P3CR.4 P3CR.3 P3CR.2 - P3CR.0
P4CR (E5H) P4CR.7 P4CR.6 P4CR.5 P4CR.4 P4CR.3 P4CR.2 P4CR.1 P4CR.0
P5CR (E6H) P5CR.7 P5CR.6 P5CR.5 P5CR.4 P5CR.3 P5CR.2 P5CR.1 P5CR.0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
34
SH79F642B
Table 7.18 Port Data Register
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
P0 (80H) P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
P1 (90H) P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0
P2 (A0H) P2.7 P2.6 P2.5 P2.4 P2.3 P2.2* P2.1* P2.0
P3 (B0H) - P3.6 P3.5 P3.4 P3.3 P3.2 - P3.0
P4 (C0H) P4.7 P4.6 P4.5 P4.4 P4.3 P4.2 P4.1 P4.0
P5 (CFH) P5.7 P5.6 P5.5 P5.4 P5.3 P5.2 P5.1 P5.0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
35
SH79F642B
Bit Number Bit Mnemonic Description
Port 2,3 output mode select
PxDRV.y 0:output drive ability of the pin is set to normal mode
2-1
x =2-3, y = 0-7 1:output drive ability of the pin is set to weak mode
(Drive current value is shown in IOH2, IOL2)
SFEN
PxPCRy
Output Mode Input Mode
VDD VDD 0 = ON
PxCRy (Pull-up)
1 = OFF
0: From Pad
1: From data register
0 = OFF
1 = ON
Second
Function
Note:
1) The input source of reading input port operation is from input pin directly.
2) The input source of reading output port operation has two paths, one is from the port data Register, and the other is from the
output pin directly. The read Instruction distinguishes which path is selected.
3) The read-modify-write instruction is for the reading of the data register in output mode, and the other instructions are for
reading of the output pin directly.
4) The destination of writing Input / Output port operation is the data register.
36
SH79F642B
7.6.4 Port Share
The 46 bi-directional I/O ports can also share second or third special function. But the share priority should obey the Outer
Most Inner Lest rule:
The out most pin function in Pin Configuration has the highest priority, and the inner most pin function has the lowest priority.
This means when one pin is occupied by a higher priority function (if enabled), it cannot be used as the lower priority
functional pin , even the lower priority function is also enabled. Only until the higher priority function is closed by hardware or
software, can the corresponding pin be released for the lower priority function use. Also the function that need pull up resister
is also controlled by the same rule.
When port share function is enabled, the user can modify PxCR, PxPCR(x=0~5), but these operations will have no effect on
the port status until the share functions was disabled.
When port share function is enabled, any read or write operation to port will only affect the data register while the port pin
keeps unchanged until all the share functions are disabled.
If the second function enables analog module such as ADC, the read instruction of pin will only return 0, regardless of the
actual pin voltage level or I/O status.
Port 0:
LCD Segment 5-12 (P0.0 – P0.7)
-RXD2(P0.6): EUART 2 data input
-TXD2(P0.7): EUART 2 data output
Table 7.21 PORT0 Share Table
Pin No. Priority Function Enable bit
1 TXD2 When Write to SBUF2 Register
Pin 48 2 SEG12 P0SS.7=1
3 P0.7 Above condition is not met
1 RXD2 Set REN2 bit in SCON2 Register, (Auto Pull up)
Pin 47 2 SEG11 P0SS.6=1
3 P0.6 Above condition is not met
1 SEG5~SEG10 P0SS.x=1 (x=0~5)
Pin 41~46
2 P0.0~P0.5 P0SS.x=0 (x=0~5)
Port 1:
LCD COM1-8 (P1.0-P1.7)
LCD Segment 1-4 (P1.4 – P1.7)
PWM0(P1.4): PWM0 output
Table 7.22 PORT1 Share Table
Pin No. Priority Function Enable bit
1 PWM0 PWM0CON Register PWM0EN=1, and P1SS.4=0
2 COM5 P1SS.4 = 1, PWM0EN=0, LCDCON DUTY[1:0]=01
Pin37
3 SEG1 P1SS.4=1 ,PWM0EN=0,
4 P1.4 Above condition is not met
1 SEG2 P1SS.5 = 1
Pin38 2 COM6 P1SS.5 = 1, LCDCON DUTY[1:0]=01
3 P1.5 Above condition is not met
1 SEG3 P1SS.6= 1
Pin39 2 COM7 P1SS.6 = 1, LCDCON DUTY[1:0]=1X
3 P1.6 P1SS.6 = 0
1 SEG4 P1SS.7= 1
Pin40 2 COM8 P1SS.7 = 1, LCDCON DUTY[1:0]=1X
3 P1.7 P1SS.7 = 0
1 COM1~4 P1SS Register COMS=1
Pin33~36
2 P1.0~P1.3 P1SS Register COMS=0
37
SH79F642B
Port 2:
———
-RST (P2.0):RESET pin
-AN0 (P2.3): ADCinput channel 0
-AN1 (P2.4): ADCinput channe 1
-AN2 (P2.5): ADCinput channe 2
-AN3 (P2.6): ADCinput channe 3
-AN5 (P2.7): ADCinput channe 5
-INT2(P2.7): external interrupt 2
-INT3(P2.6): external interrupt 3
-T1 (P2.7): Timer 1 external input
- PF(P2.4): active energy pulse output
- QF(P2.5): reactive energy pulse output
-CALIN2(P2.4): RTC calibration input
-VIN (P2.3): external voltage input
Table 7.23 PORT 2 Share Table
Pin No. Priority Function Enable bit
———
1 RST Code option
Pin19
2 P2.0 Code option
1 VIN Code option
Pin22 2 AN0 CH0=1& ADON=1&SCH [2:0] = 000
3 P2.3 CH0=0
1 AN1 CH1=1& ADON=1&SCH [2:0] = 001
2 CALOUT2 CAL2EN=1&OUTEN in register RTCCON is set ‘1’
Pin23
3 PF PFEN in EMUIE is set ‘1’
4 P2.4 CH1=0 & PFEN=0
1 AN2 CH2=1&ADON=1&SCH [2:0] = 010
Pin24 2 QF QFEN in EMUIE is set ‘1’
3 P2.5 CH2=0
1 AN3 CH3=1&ADON=1&SCH [2:0] = 011
Pin25 EX3=1&P2CR=0x40
2 INT3
( set pull up in program)
3 P2.6 Above condition is not met
1 AN5 CH5=1& ADON=1&SCH [2:0] = 101
--------
TR1=1&C/T----1----=1 (auto pull up);
2 T1
Pin26 or C/T 1 =0&TC1=1.
EX2=1&P2CR=0x80;
3 INT2
(set pull up in program)
4 P2.7 Above condition is not met
38
SH79F642B
Port 3:
-RXD0(P3.5): EUART 0 data input
-TXD0(P3.6): EUART 0 data output
-RXD1 (P3.3): EUART 1 data input
-TXD1 (P3.4): EUART 1 data output
-T0 (P3.0): TIMER0 external input or compare output
-T2 (P3.2): TIMER0 2 external input / BaudRate clock output
-T2EX(P3.0): The external clock input pin for the capture timer
-CALOUT (P3.2): RTC compensation output
-LCD Segment 29~32
- IOMUX(P3.4): Multi-function pulse output
Table 7.24 PORT 3 Share Table
Pin No. Priority Function Enable bit
--------
TR0=1&C/T----
0----
=1(auto pull up);
1 T0
Or C/T 0 =0&TC0=1
In mode0,2,3 EXEN2=1
Pin27
Or in mode 1 DCEN=1
2 T2EX Or in mode 1 DCEN=0& EXEN2=0
(auto pull up)
3 P3.0 Above condition is not met
1 CALOUT OUTEN=1 in RTCCON register
Pin28 2 T2 TR2=1& T2OE=1(auto pull up)
3 P3.2 Above condition is not met
1 RXD1 REN1=1 (auto pull up)
Pin29 2 SEG29 P3SS.3=1
3 P3.3 Above condition is not met
IOMUX[1:0]=01&PFEN=1 or IOMUX[1:0]=10&QFEN=1
1 IOMUX
Or IOMUX[1:0]=11& OUTEN=1 in RTCCON
3 SEG30 P3SS.4=1
4 P3.4 Above condition is not met
1 RXD0 REN=1 (auto pull up)
Pin31 2 SEG31 P3SS.5=1
3 P3.5 Above condition is not met
1 TXD0 Write to SBUF register
Pin32 2 SEG32 P3SS.6=1
3 P3.6 Above condition is not met
39
SH79F642B
Port 4:
LCD Segment 13-20 (P4.0 – P4.7)
Table 7.25 PORT 4 Share Table
Pin No. Priority Function Enable bit
1 SEG13~SEG20 P4SS.x=1(x=0~7)
Pin49~56
2 P4.0~P4.7 P4SS.x=0(x=0~7)
Port 5:
- LCD Segment 21-28 (P5.0 – P5.7)
- PWM1(P5.6): PWM1 output
- INT1(P5.7): External interrupt 1
Table 7.26 PORT 5 Share Table
Pin No. Priority Function Enable bit
1 SEG21~SEG26 P5SS.x=1(x=0~5)
Pin57~62
2 P5.0~P5.5 P5SS.x=0(x=0~5)
1 SEG27 P5SS.6=1
Pin63 2 PWM1 PWM1EN=1&P5SS.6=0
3 P5.6 PWM1EN=0,&P5SS.6=0
1 SEG28 P5SS.7=1
P5SS.7=0, EX1=1&set Port5.7 to input mode
Pin64 2 INT1
(set pull up in program)
3 P5.7 P5SS.7=0&EX1=0
40
SH79F642B
7.7 TIMER
7.7.1 Features
The SH79F642B has three independent 16-bit timers, Timer 0, Timer 1 and Timer 2.
Timer 0 is compatible to traditional 8051.
Timer1 is compatible to traditional 8051.
Timer2 is compatible to traditional 8052. Auto-reload mode with up or down counter and programmable output function.
Timer 0/1 is also buildup with compare output function.
Timer 0/1 clock source selection
Timer 0/1 clock source divided by
7.7.2 Timer0/1
Each regular two data registers (THx, and TLx acts as (for x = 0, 1)) can be used as a 16-bit register access. They are
controlled by the registers TCON and TMOD. The ET0 of IEN0 register and ET1 position 1 allows the Timer 0 and Timer 1
interrupt. (Refer to the interrupt section).
Timer x mode(x = 0, 1)
Counter / Timer Mode register (TMOD) way to select the bit Mx1-Mx0, select the timer works.
Mode 0: 13-bit counter / timer
Timer 'x 13 counter / timers in Mode 0. THx register store 13-bit counter / timer 8 and TLx is stored 5 (TLx.4-TLx.0). Of TLx
three (TLx.7-TLx.5) is uncertain, and should be ignored when read. When the 13-bit timer register increments, overflow, the
———
system set up timer overflow flag TFx. If the timer x interrupt is enabled, will generate an interrupt. C/ Tx selects the counter /
timer clock source.
——— ———
If the C/ Tx = 1, Timer x input pins (Tx) level from high to low transition, so that the timer x data register plus 1. C/ Tx = 0,
select the system clock timer x is the clock source.
————
When the GATEx = 0, or GATEx = 1 and the input signal INTx effective TRx is set to open the timer. GATEx set to 1 allows
———— ————
the timer to INTx by the external input signal, control, ease of measurement INTx positive pulse width. TRx position not to force
a reset timer, which means that if TRx is set, the timer register will start counting the last the TRx clear the value of 0:00.
Therefore, before enabling the timer, set the initial value of the timer register.
The register TCON1 TCLKSx (x = 0,1) select the system clock or 32.768kHz/8 as timer x (x = 0,1) of the clock source can be
configured as a timer application.
Configurable in TCLKPx (x = 0, 1) select the system clock or system clock 1/12 as the timer x (x = 0, 1) the clock source
register TCON1.
When the timer application, configuration the register TCON1 in TC0 / 1 so that the timer 0/1 overflow T0/T1 pin automatically
flip. If TC0 / 1 is set to 1, the T0/T1 pin is automatically set as an output.
System Clock
1/12
32.768KHz/8
TCLKPx Overflow
=0
TCLKSx
C/Tx TLx THx Interrupt
TFx
=1 (5bits) (8bits) Request
Tx Overflow
0:Switch Off Flag
GATEx 1:Switch On Tx
INTx + C/Tx=0 and TCx=1
&
TRx The Block Diagram of mode0 of Timerx ( x=0,1 )
41
SH79F642B
System Clock
1/12
32.768KHz/8
Overflow
TCLKPx
=0
TCLKSx
C/Tx TLx THx Interrupt
TFx
=1 (8bits) (8bits) Request
Tx Overflow
0:Switch Off Flag
GATEx 1:Switch On Tx
INTx + C/Tx=0 and TCx=1
&
TRx The Block Diagram of mode1 of Timerx ( x=0,1 )
TH0
(8bits)
System Clock
1/12
Reload
32.768KHz/8
TCLKPx
TCLKSx =0
overflow
C/Tx TL0 Interrupt
TFx
(8bits) Request
Tx =1
Overflow
Flag
0:Switch Off
GATEx 1:Switch On Tx
INTx + C/Tx=0 and TCx=1
&
TRx The Block Diagram of mode2 of Timerx (x=0,1)
42
SH79F642B
Timer 0 in Mode 3, Timer 1 can operate in modes 0, 1 or 2, but not at 1 TF1 flag and generate an interrupt. TH1 and TL1 can
only be used as a timer function, the clock source from the system clock, bit invalid GATE1. T1 input pin pull-up resistor is not
valid. Timer 1 enabled or not, because the control of TR1 Timer 0 occupied. Timer is enabled, the one in the way 0, 1 or 2:00 in
Mode 3 is turned off.
Register TCON1 the TCLKS0 select the system clock or 32.768kHz/8 as the timer clock source can be configured as a timer
application.Can be configured to register TCON1 the TCLKP0 select the system clock or system clock 1/12 as the clock source
of timer 0.
When the timer application, configuration the register TCON1 in TC0 overflow of Timer 0 T0 pin automatically flip. If TC0 is set
to 1, the T0 pin is automatically set as an output.
System Clock
1/12
32.768kHz/8
=0
TCLKP0 Overflow
C/T0 TL0 Interrupt
TCLKS0 TF0
(8bits) Request
=1
T0
Overflow
0:Switch Off Flag
GATE0 1:Switch On
T0
& C/T0=0 and TC0=1
TR0
System Clock
1/12 TH0 Overflow Interrupt
TF1
(8bits) Request
32.768kHz/8
TCLKP0 0:Switch Off Overflow
TCLKS0 1:Switch On Flag
TR1
43
SH79F642B
Registers
Table 7.27 Timer / Counter x control register (x = 0,1)
88H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
TCON TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
44
SH79F642B
45
SH79F642B
7.7.3 Timer2
The Timer 2 in the SH79F642B is the standard C52 Timer 2.It is implemented as a 16-bit register accessed as two
cascaded Data Registers: TH2 and TL2. It is controlled by the register TCON2 and TMOD2. The Timer 2 interrupt can be
enabled by setting ET2 bit in IEN0 register (See Interrupt section).
For Timer2 operation, C/T2 selects system clock (timer operation) or external pin T2 (counter operation) as the timer clock
input. Setting TR2 allows Timer 2/Counter 2 Data Register to increment by the selected input.
TCLKP2 in T2MOD selects system clock or 1/12 system clock as the Timer 2 clock source.
Timer 2 Modes
Timer 2 has three kinds of work: Capture / Reload with increment or decrement the counter of the auto-reload mode and
programmable clock output. CP/RL2 combination of selection of these ways.
Timer 2 Modes select
———
C/T2 T2OE DCEN TR2 CP/RL2 mode
X 0 X 1 1 0 16 bit capture
X 0 0 1 0
1 16 bit auto-reload timer
X 0 1 1 0
0 1 X 1 X 3 Programmable clock-output only
1 1 X 1 X X Not suggest to use this mode
X X X 0 X X Timer2 stop, the T2EX path still enable
System clock
1/12
=0 Increment Mode
TCLKP2 C/T2
TL2 TH2 TF2
T2 =1
0:Switch Off Overflow flag
TR2 1:Switch On
CP / RL2 Interrupt
& + Request
EXEN2 RCAP2L RCAP2H
0:Switch Off
1:Switch On
T2EX
EXF2
External falling
Block Diagram of 16 bit Capcture mode (Mode 0) of Timer2 edge flag
46
SH79F642B
Mode 1: 16 bit auto-reload timer
Timer 2 can be programmed to count up or down when configured in its 16-bit auto-reload mode. This feature is invoked by
DCEN (Down Counter Enable) bit in T2MOD. Upon reset, the DCEN bit is set to 0 so that timer 2 will default to count up. When
DCEN is set, Timer 2 can count up or down, depending on the value of the T2EX pin.
System clock
1/12
Increment Mode
=0
TCLKP2 C/T2 TL2 TH2 TF2
=1
T2
Overflow
0:Switch Off Flag
TR2 1:Switch On
Interrupt
+ Request
RCAP2L RCAP2H
EXEN2
+ External Falling
0:Switch Off Edge flag
T2EX 1:Switch On
EXF2
The Block Diagram of Auto Relode Mode (Mode 1)of Timer2 (DCEN=0)
Setting the DCEN bit enables Timer 2 to count up or down. When DCEN = 1, the T2EX pin controls the direction of the
count, and EXEN2’s control is invalid.
A logical “1” at T2EX makes Timer 2 count up. The timer will overflow at 0FFFFH and set the TF2 bit. This overflow also
causes the 16-bit value in RCAP2H and RCAP2L to be reloaded into the timer registers, TH2 and TL2, respectively.
A logical “0” at T2EX makes Timer 2 count down. The timer underflows when TH2 and TL2 equal the values stored in
RCAP2H and RCAP2L. The underflow sets the TF2 bit and causes 0FFFFH to be reloaded into the timer registers.
The EXF2 bit toggles whenever Timer 2 overflows or underflows and can be used as a 17th bit of resolution. In this
operating mode, EXF2 does not flag an interrupt.
47
SH79F642B
FFH FFH
System clock
1/12
=0 Interrupt
TCLKP2
Request
C/T2 TL2 TH2 TF2
T2 =1
Overflow
0:Switch Off Flag
TR2 1:Switch On
Toggle
RCAP2L RCAP2H
1.T2EX=1, Timer2 is up counter
T2EX 2.T2EX=0, Timer2 is down counter EXF2
System clock
1/12 /2
=0
TCLKP2
C/ T2 TL2 TH2
=1
0:Switch Off
TR2 1:Switch On
C/ T2
RCAP2L RCAP2H
T2OE
0:Switch Off
T2 1:Switch On
/2
EXEN2
0:Switch Off
T2EX Timer2 Interrupt
1:Switch On Request
EXF2
48
SH79F642B
Note:
(1) TF2 and EXF2 both can generate an interrupt and share the same interrupt vector address.
(2) TF2 and EXF2 can be set to ‘1’ in any conditions, and they can be cleared only by software or hardware reset.
(3) When EA = 1 and ET2 = 1, it generates the Timer 2 interrupt by setting TF2&EXF2=1.
(4) 4&5 bits in T2CON can’t be writtern other than ‘0’, otherwise T2 may not work.
49
SH79F642B
Registers
Table 7.31 Timer 2 Control register
C8H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
——— ————
T2CON TF2 EXF2 - - EXEN2 TR2 C/T2 CP/RL2
R/W R/W R/W - - R/W R/W R/W R/W
Reset Value
0 0 - - 0 0 0 0
(POR/WDT/LVR/PIN)
50
SH79F642B
51
SH79F642B
7.8 Interrupt
7.8.1 Features
14 interrupt sources
4 interrupt priority levels
Program Over Range interrupt
Outline
SH79F642B 14 interrupt sources: 3 External interrupt (external interrupt 1/2/3), three timer interrupts (timer 0/1/2), 3 EUART
interrupts, ADC interrupt, The RTC interrupt ,PWM interrupt, LPD interrupt and EMU interrupt.
52
SH79F642B
Table 7.35 Primary Interrupt Enable Register\
A9H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
IEN1 ELPD ES2 EPWM ES1 ERTC EX3 EX2 EEMU
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
53
SH79F642B
7.8.4 Interrupt Flag
Each interrupt source has its own interrupt flag, when interrupt occurs, corresponding flag will be set by hardware, the interrupt
flag bits are listed in Table bellow.
when an interrupt is generated, the hardware will be set from the corresponding flag Individual interrupt flag bits are listed
in the interrupt summary table.
For external interrupt (INT1/2/3), when an external interrupt 1/2/3 is generated, if the interrupt was edge trigged, the
interrupt flag (IE0-1 in TCON, IE2-3 in EXF0) that generated this interrupt is cleared by hardware when the service routine is
vectored. If the interrupt was level trigged, then the requesting external source directly controls the request flag, rather than the
on-chip hardware.
An external interrupt source to generate an external interrupt INTx (x = 1,2,3), if the interrupt is edge triggered, the CPU in
response to interrupt, the interrupt flag (TCON register IE1, EXF0 register of the IE2 / 3) is hardware clear; interrupt is a low
level triggered external interrupt source to the direct control of the interrupt flag, rather than controlled by the on-chip hardware.
When the timer 0/1 counter overflow, the TCON register TFx (for x = 0, 1) will generate the interrupt flag, resulting in the
Timer 0/1 interrupt the CPU after the interrupt flag is automatically cleared by hardware.
The timer 2 interrupt is generated by the logical OR of flag TF2 and bit EXF2 in T2CON register, which is set by hardware.
None of these flags can be cleared by hardware when the service routine is vectored. In fact, the service routine may have to
determine whether it was TF2 or EXF2 that generated the interrupt, so the flag must be cleared by software.
T2CON register TF2 or EXF2 flag, generate timer interrupt, the CPU after the interrupt, the flag can not be hardware
automatically cleared. In fact, the interrupt service routine must decide whether an interrupt is generated by the TF2 or EXF2
flag must be cleared by software.
The EUART interrupt is generated by the logical OR of flag RI and TI in SCON register, which is set by hardware. Neither
of these flags can be cleared by hardware when the service routine is vectored. In fact, the service routine will normally have to
determine whether it was the receive interrupt flag or the transmission interrupt flag that generated the interrupt, so the flag
must be cleared by software.
SCON register sign of RI or TI is set to 1, resulting in EUARTx (x = 0, 1) interrupt the CPU after the interrupt flag is not by
hardware automatically cleared. In fact, the interrupt service routine must determine whether the received interrupt or an
interrupt flag must be cleared by software. EUART2 EUART1 share an interrupt address.
The ADC interrupt is generated by ADCIF bit in ADCON. If an interrupt is generated, the converted result in
ADCDH/ADCDL will be valid. If continuous compare function in ADC module is Enable, ADCIF will not be set at each
conversion, but set if converted result is larger than compare value. The flag must be cleared by software.
ADCON register ADCIF flag 1:00, resulting in the ADC interrupt. If the interrupt is generated, the ADDH / ADDL the, result
of the conversion is valid. Continuous comparison function of the ADC module is turned on if the result is greater than the
comparison value, conversion, if the conversion result is less than the comparison value, the ADCIF flag 0;, ADCIF flag ADCIF
interrupt flag must be performed by software cleared.
The RTC interrupt is generated by IT0IF or DAYIF or HRIF or MINIF or SECIF or ALM1IF or ALM0IF of flag in RTCIF.
These flags must be cleared by software.
RTCIF register IT0IF or DAYIF or HRIF or MINIF or SECIF or ALM1IF or ALM0IF flag=1, resulting in RTC interrupt. These
flags must be cleared by software.
The PWM interrupts are generated by PWM0IF in PWMxCON. The flags can be cleared by software.
PWMxCON (x = 0 ~ 1) the register PWMIFx flag 1, the PWM interrupt flag must be cleared by software.
The LPD interrupt is generated by LPDIF in LPDCON register. And the flag can only be cleared by hardware.
The LPDCON register LPDIF flag is set, LPD generate an interrupt. CPU in the response of the interrupt flag is hardware
automatically clears.
Setting the corresponding EMUIF register after a energy metering period, then AND with the EMUIE register, if the result
isn’t zero, the EXF0 register EMUF flag, resulting in the EMU interrupt. The flag must be cleared by software
Table 7.36 External Interrupt Flag Register
88H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
TCON TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
54
SH79F642B
1: Timer x overflow is set by hardware; by software set to 1 will cause the timer
interrupt
Timer x to start, stop control bit
TRx
6,4 0: stop the timer x
x = 0, 1
1: Start the timer x
External interrupt x request flag
IEx
3,1 0 : No interrupt pending
x = 0,1
1 : Interrupt is pending
External interrupt x trigger mode select bit
ITx
2,0 0 : Low Level trigger
x = 0,1
1 : Trigger on falling edge
55
SH79F642B
If requests of the same priority level are pending at the start of an instruction cycle, an internal polling sequence determines
which request is serviced.
Interrupt Priority Level
Priority bits
Interrupt Level Priority
IPHx IPLx
0 0 Level 0 (lowest priority)
0 1 Level 1
1 0 Level 2
1 1 Level 3 (highest priority)
Interrupt
Interrupt Interrupt Interrupt
Signal Long Call to
Pending service
Polled Generated Interrupt Vector Service
Interrupt
Latched
56
SH79F642B
The hardware-generated LCALL pushes the contents of the program counter onto the stack (but it does not save the PSW)
and reloads the program counter with corresponding address that depends on the source of the interrupt being vectored too, as
shown in Interrupt Summary table.
Interrupt service execution proceeds from that location until the RETI instruction is encountered. The RETI instruction
informs the processor that the interrupt routine is no longer in progress, then pops the top two bytes from the stack and reloads
the program counter. Execution of the interrupted program continues from the point where it was stopped. Note that the RETI
instruction is very important because it informs the processor that the program left the current interrupt service. A simple RET
instruction would also have returned execution to the interrupted program, but it would have left the interrupt control system
thinking an interrupt with this priority was still in progress. In this case, no interrupt of the same or lower priority level would be
acknowledged.
57
SH79F642B
High-Level Threshold
Low-Level Threshold
Low-Level Threshold
58
SH79F642B
7.8.10 Interrupt Summary
Source Vector Address Enable bits Flag bits Polling Priority C51
Reset 0000h - - 0 (Highest) -
Reserved 0003h - - - -
Timer0 000Bh ET0 TF0 3 1
INT1 0013h EX1 IE1 4 2
Timer1 001Bh ET1 TF1 5 3
EUART0 0023h ES RI+TI 6 4
Timer2 002Bh ET2 TF2+EXF2 7 5
ADC 0033h EADC ADCIF 8 6
EMU 003Bh EEMU EMUF 9 7
INT2 0043h EX2 IE2 10 8
INT3 004Bh EX3 IE3 11 9
RTC 0053h ERTC RTCIF 12 10
EUART1 005Bh ES1 RI1+TI1 13 11
PWM 0063h EPWM+PWMIE0/1 PWMIF0/1 14 12
EUART2 006Bh ES2 RI2+TI2 15 13
LPD 0073h ELPD LPDIF 16 14
Reserved 007Bh - - - -
59
SH79F642B
8. Enhanced Function
The LCD driver contains a controller, 4/6/8 common signal pads and 32 segment driver pads. Segment 1~32 and
COM1~COM8 can also be used as I/O port, it is controlled by the P0SS, P1SS, P3SS , P4SS & P5SS registers.
The 32 byte display data RAM is addressed at B00H-B1FH, which could be used as data memory if needed.
The SH79F642B uses normal display topologies with contrast adjustment and which supports both 1/4duty-1/3 or 1/4 bias
and 1/8duty-1/4bias. In addition, it supports FCM (Fast Charge Mode) to reduce power cost.
The LCD supply power VLCD equals to VDD.
When SH79F642B enters the Power-Down mode, the LCD RAM can still be stored safely.
During the Power on Reset or Pin Reset or LVR Reset or Watch-dog Reset, the LCD will be turned off.
When LCD is turned off, both common and segment will output low.
V3
V2
V1
COM4 - SEGn 0
-V1
-V2
-V3
Fast Charge Mode A:
High current selected before
switching edge, period is
defined by FCCT[1:0] bits
60
SH79F642B
V3
COM1 V2
COM3
V1
0
V3
COM2 COM2 V2
V1
0
COM1
V3
COM3 V2
V1
0
V3
V2
COM4
V1
0
V3
V2
SEGn
SEGn+1 V1
SEGn 0
V3
V2
SEGn+1
V1
0
V3
V2
V1
COM4 - SEGn 0
-V1
-V2
-V3
Fast Charge Mode A:
High current selected before
switching edge, period is
defined by FCCT[1:0] bits
61
SH79F642B
COM8 V4
V3
COM7 COM1 V2
COM6
V1
0
COM5
V4
COM4
COM3 V3
COM2 V2
COM1
COM2 V1
V4
V3
COM3 V2
V1
V4
V3
COM4 V2
SEGn V1
V4
V3
SEGn V2
V1
V4
V3
V2
V1
COM1- SEGn 0
- V1
- V2
- V3
-V4
62
SH79F642B
8.1.2 Registers
Table 8.1 LCD Control Register
A3H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
LCDCON LCDON - DUTY1 DUTY0 BIAS CONTR2 CONTR1 CONTR0
W/R W/R - W/R W/R W/R W/R W/R W/R
Reset Value
0 - 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
63
SH79F642B
Table 8.3 P0 fuction select register
AAH Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
P0SS P0S7 P0S6 P0S5 P0S4 P0S3 P0S2 P0S1 P0S0
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
64
SH79F642B
P4 mode control:
7-0 P4S[7:0] 0: P4.0~P4.7 as I/O
1: P4.0~P4.7 as Segment(SEG13 – SEG20)
65
SH79F642B
8.1.3 LCD RAM config
Table 8.8 LCD 1/4 duty, 1/3 bias (COM1 – 4, SEG1 – 39)
7 6 5 4 3 2 1 0
Address
- - - - COM4 COM3 COM2 COM1
B00H - - - - SEG1 SEG1 SEG1 SEG1
B01H - - - - SEG2 SEG2 SEG2 SEG2
B02H - - - - SEG3 SEG3 SEG3 SEG3
B03H - - - - SEG4 SEG4 SEG4 SEG4
B04H - - SEG5 SEG5 SEG5 SEG5 SEG5 SEG5
B05H - - SEG6 SEG6 SEG6 SEG6 SEG6 SEG6
B06H SEG7 SEG7 SEG7 SEG7 SEG7 SEG7 SEG7 SEG7
B07H SEG8 SEG8 SEG8 SEG8 SEG8 SEG8 SEG8 SEG8
B08H SEG9 SEG9 SEG9 SEG9 SEG9 SEG9 SEG9 SEG9
B09H SEG10 SEG10 SEG10 SEG10 SEG10 SEG10 SEG10 SEG10
B0AH SEG11 SEG11 SEG11 SEG11 SEG11 SEG11 SEG11 SEG11
B0BH SEG12 SEG12 SEG12 SEG12 SEG12 SEG12 SEG12 SEG12
B0CH SEG13 SEG13 SEG13 SEG13 SEG13 SEG13 SEG13 SEG13
B0DH SEG14 SEG14 SEG14 SEG14 SEG14 SEG14 SEG14 SEG14
B0EH SEG15 SEG15 SEG15 SEG15 SEG15 SEG15 SEG15 SEG15
B0FH SEG16 SEG16 SEG16 SEG16 SEG16 SEG16 SEG16 SEG16
B10H SEG17 SEG17 SEG17 SEG17 SEG17 SEG17 SEG17 SEG17
B11H SEG18 SEG18 SEG18 SEG18 SEG18 SEG18 SEG18 SEG18
B12H SEG19 SEG19 SEG19 SEG19 SEG19 SEG19 SEG19 SEG19
B13H SEG20 SEG20 SEG20 SEG20 SEG20 SEG20 SEG20 SEG20
B14H SEG21 SEG21 SEG21 SEG21 SEG21 SEG21 SEG21 SEG21
B15H SEG22 SEG22 SEG22 SEG22 SEG22 SEG22 SEG22 SEG22
B16H SEG23 SEG23 SEG23 SEG23 SEG23 SEG23 SEG23 SEG23
B17H SEG24 SEG24 SEG24 SEG24 SEG24 SEG24 SEG24 SEG24
B18H SEG25 SEG25 SEG25 SEG25 SEG25 SEG25 SEG25 SEG25
B19H SEG26 SEG26 SEG26 SEG26 SEG26 SEG26 SEG26 SEG26
B1AH SEG27 SEG27 SEG27 SEG27 SEG27 SEG27 SEG27 SEG27
B1BH SEG28 SEG28 SEG28 SEG28 SEG28 SEG28 SEG28 SEG28
B1CH SEG29 SEG29 SEG29 SEG29 SEG29 SEG29 SEG29 SEG29
B1DH SEG30 SEG30 SEG30 SEG30 SEG30 SEG30 SEG30 SEG30
B1EH SEG31 SEG31 SEG31 SEG31 SEG31 SEG31 SEG31 SEG31
B1FH SEG32 SEG32 SEG32 SEG32 SEG32 SEG32 SEG32 SEG32
66
SH79F642B
8.2 EUART0
8.2.1 Features
The SH79F642B has three enhanced EUARTs with own baud rate generator
The baud rate generator is an 15 bit up-counting timer
Enhancements over the standard 8051 the EUART include Framing Error detection and automatic address recognition
The EUART can be operated in four modes
The UART1 provide IR interface.
67
SH79F642B
Transmit Shift Register
TX CLOCK TI
SM2 0 1 SERIAL Serial Port Interrupt
CONTROLLER RI
RX CLOCK
SHIFT
TXD
CLOCK
RI LOAD SBUF
RX START
REN
RX SHIFT
Read SBUF
CLOCK
PAROUT SBUF SBUF
RXD SIN
Any instruction that uses SBUF as a destination register (“write to SBUF” signal) will start the transmission. The next system
clock tells the Tx control block to commence a transmission. The data shift occurs at the falling edge of the SHIFT CLOCK, and
the contents of the transmit shift register is shifted one position to the right. As data bits shift to the right, zeros come in from the
left. After transmission of all 8 bits in the transmit shift register, the Tx control block will deactivates SEND and sets TI (SCON.1)
at the rising edge of the next system clock.
Write to SBUF
RxD
D0 D1 D2 D3 D4 D5 D6 D7
TxD
TI
68
SH79F642B
Reception is initiated by the condition REN (SCON.4)= 1 and RI (SCON.0) = 0. The next system clock activates RECEIVE. The
data latch occurs at the rising edge of the SHIFT CLOCK, and the contents of the receive shift register are shifted one position to
the left. After the receiving of all 8 bits into the receive shift register, the RX control block will deactivates RECEIVE and sets RI
at the rising edge of the next system clock, and the reception will not be enabled till the RI is cleared by software.
RxD
D0 D1 D2 D3 D4 D5 D6 D7
TxD
RI
STOP
Internal
PARIN
Data Bus
Baud rate
Write to SBUF START SOUT TXD
Generator
LOAD
overflow CLOCK
From 7FFF to 0000
TX START TX SHIFT
÷ 16 TX CLOCK
TI
SERIAL
Serial Port Interrupt
CONTROLLER
÷16 RI
RX CLOCK
SAMPLE LOAD SBUF
Read SBUF
1-TO-0 RX START RX SHIFT
DETECTOR
CLOCK Internal
PAROUT SBUF
Data Bus
BIT
RXD SIN D8 RB8
DETECTOR
69
SH79F642B
Transmission begins with a “write to SBUF” signal, and it actually commences at the next system clock following the next rollover
in the divide-by-16 counter (divide baud-rate by 16), thus, the bit times are synchronized to the divide-by-16 counter, not to the
“write to SUBF” signal. The start bit is firstly put out on TxD pin, then are the 8 bits of data. After all 8 bits of data in the transmit
shift register are transmitted, the stop bit is put out on the TxD pin, and the TI flag is set at the same time that the stop is send.
Write to SBUF
TxD
Start D0 D1 D2 D3 D4 D5 D6 D7 Stop
Shift CLK
TI
Bit Sample
Shift CLK
RI
70
SH79F642B
RX CLOCK
SAMPLE LOAD SBUF
1-TO-0 Read SBUF
RX START RX SHIFT
DETECTOR
CLOCK Internal
PAROUT SBUF
Data Bus
BIT
RXD SIN D8 RB8
DETECTOR
th
Transmission begins with a “write to SBUF” signal, the “write to SBUF” signal also loads TB8 into the 9 bit position of the
transmit shift register. Transmission actually commences at the next system clock following the next rollover in the divide-by-16
counter (thus, the bit times are synchronized to the divide-by-16 counter, not to the “write to SUBF” signal). The start bit is firstly
put out on TxD pin, then are the 9 bits of data. After all 9 bits of data in the transmit shift register are transmitted, the stop bit is put
out on the TxD pin, and the TI flag is set at the same time, this will be at the 11th rollover of the divide-by-16 counter after a write
to SBUF.
Write to SBUF
TxD
Start D0 D1 D2 D3 D4 D5 D6 D7 D8 Stop
Shift CLK
TI
71
SH79F642B
Reception is enabled only if REN is high. The serial port actually starts the receiving of serial data, with the detection of a falling
edge on the RxD pin. For this purpose RxD is sampled at the rate of 16 times baud rate. When a falling edge is detected, the
divide-by-16 counter is immediately reset. This helps to align the bit boundaries with the rollovers of the divide-by-16 counter.
The 16 states of the counter divide each bit time into 16ths. The bit detector samples the value of RxD at the 7th, 8th and 9th
counter state of each bit time. The value accepted is the value that was seen in at least 2 of the 3 samples. This is done for noise
rejection. If the first bit detected after the falling edge of RxD pin is not 0, which indicates an invalid start bit, and the reception is
immediately aborted. The receive circuits are reset and again looks for a falling edge in the RxD line. If a valid start bit is
detected, then the rest of the bits are also detected and shifted into the shift register.
After shifting in 9 data bits and the stop bit, the SBUF and RB8 are loaded and RI is set if the following conditions are met:
1. RI must be 0
th
2. Either SM2 = 0, or the received 9 bit = 1 and the received byte accords with Given Address
th
If these conditions are met, then the 9 bit goes to RB8, the 8 data bits go into SBUF and RI is set. Otherwise the received
frame may be lost.
At the time, the receiver goes back to looking for another falling edge on the RxD pin. And the user should clear RI by software for
further reception.
RxD
Start D0 D1 D2 D3 D4 D5 D6 D7 D8 Stop
Bit Sample
Shift CLK
RI
STOP
TB8 D8
Internal
PARIN SOUT TXD
Baud rate Data Bus
Generator Write to SBUF START
LOAD
overflow
CLOCK
From 7FFF to 0000
TX START TX SHIFT
÷ 16 TX CLOCK
TI
SERIAL
Serial Port Interrupt
CONTROLLER
÷16 RI
RX CLOCK
SAMPLE LOAD SBUF
Read SBUF
1-TO-0 RX START RX SHIFT
DETECTOR
CLOCK Internal
PAROUT SBUF
Data Bus
BIT
RXD SIN D8 RB8
DETECTOR
72
SH79F642B
8.2.3 Baud rate Generator
EUART0, EUART1, EUART2 each carry a baudrate generator, It is essentially a 15-bit up counter.
Overflow To EUART
15-bit timer `
Fsys From 7FFFH to
0000H
SBRTEN=1
SBRTH[14:8],SBRTL[7:0]
Fsys
The baudrate is SBRToverflowrate = , SBRT = [ SBRTH , SBRTL]
32768 − SBRT
so, the baud rate is calculated as follows in each mode.
In Mode 0, the baud rate is programmable system clock 1/12 or 1/4 determined by the SM2 bit. When SM2=0, t the serial port
runs at 1/12 of the system clock. When SM2 =1, the serial port runs at 1/4 of the system clock.
In mode 1 and 3, the baud rate can be fine fixed with accuracy of one system clock. The formula is shown below:
Fsys
BaudRate =
16 × (32768 - SBRT ) + SFINE
E.G. When Fsys=8MHz, to get 115200Hz baud rate,computing method of SBRT and SFINE as shown below:
8000000/16/115200 = 4.34
SBRT = 32768 – 4 = 32764
115200 = 8000000/(16×4 + SFINE)
SFINE = 5.4 ≈ 5
The method with fine register comes into a 115942Hz Baudrate with 0.64% error compared to 8.5% error of calculating in old
method.
In Mode 2, the baud rate is fixed for the system clock 1/32 or 1/64, determined by the SMOD bit (PCON.7). When the SMOD bit
to 0, EUART to 1/64 of the system clock is running. When SMOD bit is 1, EUART run the system clock 1/32.
f SYS
BaudRate = 2 SMOD × ( )
64
73
SH79F642B
8.2.4 Multi-processor communication
Software address recognition
Modes 2 and 3 of the EUART have a special provision for multi-processor communication. In these modes, 9 data bits are
received. The 9th bit goes into RB8. Then a stop bit follows. The EUART can be programmed such that when the stop bit is
received, the EUART interrupt will be activated (i.e. the request flag RI is set) only if RB8 = 1. This feature is enabled by setting
the bit SM2 in SCON.
A way to use this feature in multiprocessor communications is as follows. lf the master processor wants to transmit a block of
data to one of the several slaves, it first sends out an address byte which identifies the target slave. An address byte differs from
a data byte in that the 9th bit is 1 in an address byte and 0 in a data byte.
With SM2 = 1, no other slave will be interrupted by a data byte. An address byte, however, will interrupt all slaves, so that each
slave can examine the received byte and see if it is being addressed. The addressed slave will clear its SM2 bit and prepare to
receive the data bytes that will be coming. After having received a complete message, the slave sets SM2 again. The slaves
that were not addressed leave their SM2 set and go on with their business, ignoring the incoming data bytes.
Note: In mode 0, SM2 is used to select baud rate doubling. In mode 1, SM2 can be used to check the validity of the stop bit. If
SM2 = 1 in mode 1, the receive interrupt will not be activated unless a valid stop bit is received.
The Automatic Address Recognition feature allows a master to selectively communicate with one or more slaves by
invoking the Given Address. All of the slaves may be contacted by using the Broadcast address.
Two special Function Registers are used to define the slave’s address, SADDR, and the address mask, SADEN. The
slave address is an 8-bit value specified in the SADDR register. The SADEN register is actually a mask for the byte value in
SADDR. If a bit position in SADEN is 0, then the corresponding bit position in SADDR is don’t care. Only those bit positions in
SADDR whose corresponding bits in SADEN are 1 are used to obtain the Given Address. This gives the user flexibility to
address multiple slaves without changing the slave address in SADDR. Use of the Given Address allows multiple slaves to be
recognized while excluding others.
Slave 1 Slave 2
SADDR 10100100 10100111
SADEN (0 mask) 11111010 11111001
Given Address 10100x0x 10100xx1
Broadcast Address (OR) 1111111x 11111111
The Given address for slave 1 and 2 differ in the LSB. For slave 1, it is a don’t care, while for slave 2 it is 1. Thus to communicate
only with slave 1, the master must send an address with LSB = 0 (10100000). Similarly the bit 1 is 0 for slave 1 and don’t care for
slave 2. Hence to communicate only with slave 2 the master has to transmit an address with bit 1 = 1 (1010 0011). If the master
wishes to communicate with both slaves simultaneously, then the address must have bit 0 = 1 and bit 1 = 0. The bit 2 position is
don’t care for both the slaves. This allows two different addresses to select both slaves (1010 0001 and 1010 0101).
The master can communicate with all the slaves simultaneously with the Broadcast Address. This address is formed from the
logical OR of the SADDR and SADEN. The zeros in the result are defined as don’t cares. In most cases, the Broadcast Address
is FFh, this address will be acknowledged by all slaves.
74
SH79F642B
On reset, the SADDR and SADEN are initialized to 00h. This results in Given Address and Broadcast Address being set as
XXXXXXXX (all bits don’t care). This effectively removes the multiprocessor communications feature, since any selectivity is
disabled. This ensures that the EUART 0 will reply to any address, which it is backwards compatible with the 80C51
microcontrollers that do not support automatic address recognition. So the user may implement multiprocessor by software
address recognition mentioned above.
Error Detection
Error detection is available when the SSTAT bit in register PCON is set to logic 1.The SSTAT bit must be logic 1 to access any
of the status bits (FE, RXOV, and TXCOL). The SSTAT bit must be logic 0 to access the Mode Select bits (SM0, SM1, and
SM2).All the 3 bits should be cleared by software after they are set, even when the following frames received without any error
will not be cleared automatically.
Transmit collision
The Transmit Collision bit (TXCOL bit in register SCON) reads ‘1’ if RI is set 0 and user software writes data to the SBUF
register while a transmission is still in progress. If this occurs, the new data will be ignored and the transmit buffer will not be
written.
Receive Overrun
The Receive Overrun bit (RXOV in register SCON) reads ‘1’ if a new data byte is latched into the receive buffer before software
has read the previous byte. The previous data is lost when this happen.
Frame Error
The Frame Error bit (FE in register SCON) reads ‘1’ if an invalid (low) STOP bit is detected.
Break Detection
A break is detected when any 11 consecutive bits are sensed low. Since a break condition also satisfies the requirements for a
framing error, a break condition will also result in reporting a framing error. Once a break condition has been detected, the
EUART will go into an idle state and remain in this idle state until a valid stop bit (rising edge on RxD line) has been received.
8.2.5 EUART1/2
EUART1/2 has the same control & operation modes as EUART0. EUART1 provides IR interface.(Refer to IR section for
details)
8.2.6 Register
Table 8.10 Power Control register
87H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
PCON SMOD SSTAT SSTAT1 SSTAT2 GF1 GF0 PD IDL
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
75
SH79F642B
Table 8.11 EUART0 Control & status Register
98H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SCON SM0/FE SM1/RXOV SM2/TXCOL REN TB8 RB8 TI RI
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
76
SH79F642B
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
77
SH79F642B
3-0 SFINE[3:0] EUART0 baudrate generator fine data register
78
SH79F642B
Table 8.17 EUART1 Data buffer register
D9H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SBUF1 SBUF1.7 SBUF1.6 SBUF1.5 SBUF1.4 SBUF1.3 SBUF1.2 SBUF1.1 SBUF1.0
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
79
SH79F642B
Table 8.20 EUART2 Control & status Register
F8H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SCON2 SM20/FE2 SM21/RXOV2 SM22/TXCOL2 REN2 TB82 RB82 TI2 RI2
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
80
SH79F642B
Table 8.21 Data buffer register
BAH Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SBUF2 SBUF2.7 SBUF2.6 SBUF2.5 SBUF2.4 SBUF2.3 SBUF2.2 SBUF2.1 SBUF2.0
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
81
SH79F642B
Number Mnemonic Description
3-0 SFINE2[3:0] EUART2 baudrate generator fine data register
IRON
IRTXD TXD 1
Carrier
RXD Mux
EUART 1 TXD RXD 1
IRON
Fcarry
TXD
IRTXD
82
SH79F642B
8.4 ADC
8.4.1 feature
10-bit resolution
Built-in reference voltage
5 analog channel input
The SH79F642B include a single ended, 10-bit SAR Analog to Digital Converter (ADC) with build in Vref connected to the
VDD or AVREF. 5 ADC channels are share with one ADC module, each channel can be programmed to connect with the
————
analog input individually. Only one channel can be available at one time. GO/DONE signal is available to start convert, and
indicate end of convert. When onversion is completed, the data in AD convert data register will be updated and ADCIF bit in
ADCON register will be set to generate an interrupt if ADC Interrupt is enabled.
The ADC integrated a digital compare function to compare the value of analog input with the digital value in the AD
converter. If this function is enabled (EC =1 in ADCON register) when ADC module is enabled (ADON = 1 in ADCON register).
When the corresponding digital value of analog input is larger than the value in compare value register (ADDH/L), the ADC
————
interrupt will occur, otherwise no interrupt will be generated. The digital comparator can work continuously when GO/DONE bit
is set until software clear, which behaviors different with the ADC module.
The ADC module including digital compare module can wok in IDLE mode and the ADC interrupt will wake up the Idle
mode, but is disabled in POWER-DOWN mode.
Measurement of the battery voltage to the ADC, the internal first pass through the resistor divider (divider resistor value is
10k/10k). The ADC measurement is 1/2 the battery voltage, each LSB corresponding ( VDD/512 )mV.
000
AN0
001
AN1
010
10 bit AN2
SAR 011
AN3
ADC Input voltage 101
AN5
100
VBAT
110
Regulator
83
SH79F642B
8.4.3 Register
Table 8.26 ADC Control Register
C1H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
————
ADCON ADON ADCIF EC EADC SCH2 SCH1 SCH0 GO/DONE
R/W R/W R/W R/W R/W R/W R/W R/W R/W
Reset Value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
84
SH79F642B
2 tAD ≤ Sample time = (TS [3:0]+1) * TAD < 15 TAD
Note:
(1) Make sure that tAD ≧ 1µs;
(2) The minimum sample time is 2 tAD, even TS[3:0] = 0000;
(3) The maximum sample time is 15 tAD , even TS[3:0] = 1111;
(4) Evaluate the series resistance connected with ADC input pin before set TS[3:0];
(5) Be sure that the series resistance connected with ADC input pin is no more than 10kΩ when 2 tAD sample time is selected;
(6) Total conversion time is: 12 tAD + sample time.
85
SH79F642B
4. Enable the ADC module with the selected analog channel.
————
5. Set GO/DONE = 1 to start the compare function.
6. If the analog input is lager than compare value set in ADDH/ADDL, the ADCIF will be set to 1. if the ADC interrupt is enabled,
the ADC interrupt will occur.
————
7. The compare function will continue work until the GO/DONE bit is cleared to 0.
86
SH79F642B
8.5 RTC (Real Timer Clock)
8.5.1 Features
32.768kHz clock input with frequency compensation.
Built-in high-precision frequency compensation circuit, compensation accuracy: 0.127PPM.
Counter registers for: Half second, Second, Minute, Hour, Day, Day-of-week, Month, Year
Day counter with automatic month and leap year adjustment
Provides two Real Time Clock Alarms and a Timer.
Provides the accurate seconed pulse output.
SCBC’s value is equal to high 8 bit of 1 Hz frequency divider (source from 32.768KHz). Write 0x00 to SCBC will clear the high
8 bit register of divider. So SCBC also can be used for correcting time difference.
Compensation:
A frequency compensation mechanism is built into this RTC module to allow adjustments to the RTC clock when a less
accurate 32.768kHz crystal is used. With the compensation mechanism, a more accurate real time could be made than the
frequency accuracy of the crystal that drives the module. The compensation value can be be set by application software, the
compensation cycle is 60s (high frequency compensaton second pulse’s compensaton cycle is 1s).1 LSB of compensaton
register can correct 0.127 PPM (1/60/32768/4) frequency error. There are 13 bit register ( two's complement ) use for
compensation, and higest bit reflect the polarity ( 0 means the crystal is too fast, 1 means the crystal is too slow). The
compensation range is -1024PPM to 1024PPM. The relation of frequency error (Err, Unit:S/D) and compensaton value (E) as
follow:
Err > 0 E(13:0) = Err * 11.574 / 0.127
Err < 0 E(13:0) = ~( |Err| * 11.574 / 0.127 ) + 1
87
SH79F642B
Alarm Function
Built-in 2 group alarm, one group include Second, Minute, Hour, Day, Day-of-week alarm register, the other one include
Second, Minute, Hour alarm register. When the time register data equal the alarm register, ALM0(1) be set to 1 and alarm
interrupt generate ( when alarm interrupt is enabled). At the same time, if OUTF[1:0] = 11, alarm 1 will output a 80ms(±1ms)
pulse in CALOUT.
ALMCON use to enable or disable each alarm register, There is no rule set to check the alarm register data, but the wrong data
may cause unexpected result. Therefore, take care in software programming.
Timer Function
Build-in 8 bit timer, the timer’s clock source can be choose by set ITS[1:0]. ITEN is a bit to control disable/enable timer function.
When the timer overflow, the timer register ( RTCTMR ) auto reload, set ITIF = 1, generate timer interrupt (if the interrupt is
enabled).
Interrupt Funtion
Provides second, minute, hour interrupt and alarm, timer interrupt. Each interrupt include interrupt control bit and interrupt flag
bit, the interrupt flag can be set 1 by hardware and clear by software.
I/O Pin
The RTC function uses 1 I/O pin: CALOUT. CALOUT is controlled by output control register OUTF, CALOUT output pin for:
compensated clock output after calibration, which can be programmed to output compensated 60-second clock or its original
32KHz clock, period changing signal. The output polarity can be set by OUTS.
8.5.3 Registers
88
SH79F642B
89
SH79F642B
Table 8.36 Month Register
FFA5H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
MTH - - - MTH4 MTH3 MTH2 MTH1 MTH0
R/W - - - R/W R/W R/W R/W R/W
Reset Value (POR) - - - * * * * *
Reset Value(WDT/LVR/PIN) - - - u u u u u
90
SH79F642B
Reset Value - - u u u u u u
(WDT/LVR/PIN) - - u u u u u u
91
SH79F642B
92
SH79F642B
93
SH79F642B
94
SH79F642B
Only RTCPSW = 0x5a, the calendar time register value update to the calendar time
counter,any other value can affect the calendar time counter.Finished writing
7-0 PSW7-0
value,whether the data is valid,the register only can be cleared by hardware.The
register can be written onle if RTCWR = 0x69.
95
SH79F642B
The Request Flag for Minute Interrupt
4 MINIF 0: No request
1: Request
The Request Flag for Second Interrupt
3 SECIF 0: No request
1: Request
The Request Flag for Alarm 1 Interrupt
2 ALM1IF 0: No request
1: Request
The Request Flag forAlarm 0 Interrupt
1 ALM0IF 0: No request
1: Request
96
SH79F642B
The SH79F642B has two 12-bit PWM modules. The PWM module can provide the pulse width modulation waveform with the
period and the duty being controlled, individually. The PWMxEN (x = 0-1) is used to enable two PWM modules. The PWMxCON
(x = 0-1) is used to control the clock source, output mode and cycle interrupt of the PWM module output, and so on. The
PWMxPH/L (x = 0-1) is used to control the period cycle of the PWM module output. PWMxDH/L (x = 0-1) is used to control the
duty in the waveform of the PWM module output.
0
12-bit Period 12-bit Duty PWM 1
Counter Counter Wave 1 PWM
'1' Match 0
Interrupt
PWMCON[PWMIE] PWMCON[PWMIF]
Control
8.6.2 Registers
Table 8.56 PWMx control PWMxCON (x=0~1)
C3H, 93H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
PWM0CON (C3H) PWM0EN PWM0S PWM0CK1 PWM0CK0 - PWM0IE PWM0IF PWM0SS
PWM1CON (93H) PWM1EN PWM1S PWM1CK1 PWM1CK0 - PWM1IE PWM1IF PWM1SS
W/R W/R W/R W/R W/R - W/R W/R W/R
Reset Value
0 0 0 0 - 0 0 0
(POR/WDT/LVR/PIN)
97
SH79F642B
PWMx clock selector:
00: system clock/1
5~4 PWMxCK[1:0] 01: system clock/2
10: system clock/4
11: system clock/8
PWMx interrupt control :
2 PWMxIE 0:Disable PWMx period interrupt
1:Enable PWMx period interrupt
PWMx interrupt flag
1 PWMxIF 0: no overflow
1: Set by hardware to indicate that the PWM period counter overflow.Cleared by software
PWMx output control
0 PWMxSS 0:PWMx output disable, as I/O or other fuction
1:PWMx output enable
98
SH79F642B
12-bit PWM duty registers
1. If PWM0P ≤ PWM0D,
PWM0 outputs high level when the PWM0S bit is cleared to 0.
11-0 PWM0D.11~0 PWM0 outputs GND level when the PWM0S bit is setted to 1.
2. If PWM0D = 00H,
PWM0 outputs GND level when the PWM0S bit is cleared to 0.
PWM0 outputs high level when the PWM0S bit is setted to 1.
Note: The change of PWMxPH will take affect at the next PWMx period. The user must change PWMxPL at first, and then
change PWMxPH for changing PWMx period.
99
SH79F642B
6 Tsys
PWMSS = 1
5 5 5 5
4 4 4
3 3 3
Period Counter
2 2
1 1
4 4 4
3 3 3
Duty Counter 2 2 2
1 1
System
Clock
PWM Clock
PWMEN
Duty Zone
Duty Zone
PWM pin output
when PWMS = 1
100
SH79F642B
8.6.6 PWM Programming Note
I. If PWMxEN=1&PWMxSS=0, PWMx output will shut down (used as normal I/O), and PWMx can be used as a 12-bit timer.
Meanwhile, if EPWM=1 in interrupt control register IEN1and PWMxIE=1 in PWMxCON and EA = 1, PWMx interrupt will occur
(unless PWMxP = 0).
II. When PWMxP=0& PWMxSS=1&PWMxEN=1, P1.4/P5.6 outputs the value of PWMxS no matter what value PWMxD is.
III. When 0 < PWMxP ≤ PWMxD, PWMSS = 1 and PWMxEN = 1:
If PWMxS=0, P1.4/P5.6 outputs high level;
If PWMxS=1, P1.4/P5.6 outputs low level.
IV. When PWMxD=0, PWMxP > 0, PWMxSS = 1 and PWMxEN = 1:
If PWMxS=0, P1.4/P5.6 outputs low level;
If PWMxS=1, P1.4/P5.6 outputs high level.
V. When PWMxEN = 0:
If PWMxS=0, P1.4/P5.6 outputs low level;
If PWMxS=1, P1.4/P5.6 outputs high level.
101
SH79F642B
8.7 Low-voltage detection (LPD1)
Low-voltage detection (LPD1) used to monitor the VDD voltage and the voltage of the VIN pin. VIN pin voltage detection
function code selection. If the VIN pin detection is effective VIN pin voltage is below 1.2V, the hardware setup to mark FVIN 0;
if the pin voltage is above 1.2V, the hardware set FVIN mark of 1. Low-voltage detection circuit detects the VDD voltage lower
than 2.7V, the hardware setup the mark FVDD 0; higher than 2.7V to VDD is detected, the hardware setup the mark FVDD 1.
The low voltage detection to provide the VIN pin and VDD voltage marker to the power management features, but only the VDD
voltage marker to the automatic switching of the power supply.
Table 8.61 Low-voltage detection control register
B3H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
LPDCON LPDEN FVIN LPDIF VOUTS FVDD LPDS - AUTOS
W/R W/R R W/R W/R R R - W/R
0 0
Reset value u u
1 0 0 0 0 -
(POR/WDT/LVR/PIN) 0 0
0 0
102
SH79F642B
0: Set to ‘1’ by hardware when VOUT>LPD detect voltage.
Notes:When LPDEN=0, LPDF=0.
LPD Voltage Control bits
000: 2.55 V
001: 2.70 V
010: 2.85 V
3-0 LPDS [2:0] 011: 3.00 V
100: 3.15 V
101: 3.30 V
110: 3.45 V
111: 3.60 V
103
SH79F642B
8.8Low Voltage Reset (LVR)
8.8.1 Features
TLVR is about 30-60us.
An internal reset indicates low voltage reset generates, when VDD ≤ VLVR
The LVR function is used to monitor the supply voltage and generate an internal reset in the device when the supply
voltage is below the specified value VLVR. The LVR de-bounce Timer TLVR is about 30-60us.
The LVR circuit has the following functions when the LVR function is enabled: (t means the time of the supply voltage
below VLVR)
- Generates a system reset when VDD ≤ VLVR and t ≥ TLVR.
- Cancels the system reset when VDD > VLVR or VDD < VLVR, but t < TLVR.
The LVR function is enabled by the Code Option.
It is typically used in AC line or large battery supplier applications, where heavy loads may be switched on and cause the
MCU supply-voltage temporarily falls below the minimum specified operating voltage. This feature is can protect system from
working under bad power supply environment.
104
SH79F642B
Power On Reset Flag
Set only by Power On Reset, cleared only by software
5 PORF
0: No Power On Reset.
1: Power On Reset occurred.
Low Voltage Reset Flag
Set only by Low Voltage Reset, cleared by software or Power On Reset
4 LVRF
0: No Low Voltage Reset occurs
1: Low Voltage Reset occurred
External Pin Reset Flag
Set only by External Pin Reset, cleared by software or Power On Reset
3 CLRF
0: No External Pin Reset occurs
1: External Pin Reset occurred
WDT Overflow period control bit
000: Overflow period minimal value = 4096ms
001: Overflow period minimal value = 1024ms
010: Overflow period minimal value = 256ms
011: Overflow period minimal value = 128ms
2-0 WDT[2:0] 100: Overflow period minimal value = 64ms
101: Overflow period minimal value = 16ms
110: Overflow period minimal value = 4ms
111: Overflow period minimal value = 1ms
Notes: If WDT_opt is enable in application, user must clear WatchDog
periodically, and the interval must be less than the value list above.
105
SH79F642B
8.10 Power Management
SH79F642B provides two power supply, an external power input from the VDD pin switch to VOUT, a battery from the VBAT pin
switch to VOUT. The normal power supply external power supply, if the external power failure situation, the automatic cut by the
external power supply to the battery-powered; if the external power supply to restore power, then automatically switch to
battery-powered external power supply. The external power supply voltage detection by the built-in low voltage detector LPD
implementation.
The VOUT powered all the features of the circuit except for the analog front-end of Energy Metering. The analog front-end of
Energy Metering is supported by VDD or LDO. LDO is powered by VOUT.
In order to cooperate with different power source, SH79F642B provides low power cost mode to meet working requirement with
lower power needs.
106
SH79F642B
8.10.2 Power mode
Depending on the available power, corresponding to the two power modes: Normal Power Mode and Battery-powered Mode.
The power mode switchs automatically by the power management or under software control. Automatic switching function can
be disabled or enabled by adjusting registers. No matter the device is powered by the external power supply VDD or battery
supply, or both of them, SH79F642B can work properly anyway.
Functions always work CPU, RTC, External Interrupt RTC, External Interrupt RTC, External Interrupt
8.10.2.2 Battery-powered
In battery-powered mode SH79F642B is supplied by battery, and external power supply is shut down. Other functions can be
controlled by software.
Table 8.66 The Working Status of the Function Modules In Battery Mode
Mode
Normal Idle Power-Down
Function
CPU,EUART0 & 1 & 2,
Disabled Functions - CPU ADC, TIMER0 & 1 & 2,
PWM0 & 1
Functions controlled
WDT, LVR WDT, LVR WDT, LVR
by Code Option
Functions always work CPU, RTC, External Interrupt RTC, External Interrupt RTC, External Interrupt
107
SH79F642B
In normal power supply mode, if the VIN pin voltage detection function is invalid (disabled by LPD registers), and low-voltage
detection (LPD) has detected that the VDD pin voltage is below 2.7V, it would cause the LPD interrupt, and the device would
switch to the battery-powerred mode immediately.
In battery-powered mode, the VIN pin voltage detection function is invalid (disabled by LPD registers), and if low-voltage
detection (LPD) has detected that the VDD pin voltage is above 2.7V, the device would switch to normal power mode with
external power supply and generate the LPD interrupt request. If the VIN pin voltage detection (allowed by LPD registers) is
valid, and low-voltage detection (LPD) has detected that the VIN pin voltage is above 1.2V, it would cause the LPD interrupt
again.
Automatic switching function can be allowed or disabled by AUTOS (LPDCON.0). To ensure no misuse writings occur, like the
way entering power saving mode, it requires to write 55H to the power switching control register first, and then clear or set
AUTOS (LPDCON. 0). The instructions must be continuous, otherwise automatic switching function is invalid.
If the automatic switching function is disabled by AUTOS (LPDCON.0), the power mode switch can also be implemented by
software. To ensure no misuse writings occur, like the way entering power saving mode, it requires to write 55H to the power
switching control register first, and then to configure the power supply. Otherwise automatic switching function is invalid.
8.10.3 Register
Table 8.67 LPD control register
B3H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
LPDCON LPDEN FVIN LPDIF VOUTS FVDD LPDS - AUTOS
W/R W/R R W/R W/R R R - W/R
0 0
Reset value u u
1 0 0 0 0 -
(POR/WDT/LVR/PIN) 0 0
0 0
108
SH79F642B
Table 8.68 Power switching control register
E7H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
PASLO PASLO.7 PASLO.6 PASLO.5 PASLO.4 PASLO.3 PASLO.2 PASLO.1 PASLO.0
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
109
SH79F642B
Program example:
IDLE_MODE:
MOV SUSLO, #55H
ORL PCON, #01H
NOP
NOP
NOP
POWERDOWN_MODE:
MOV SUSLO, #55H
ORL PCON, #02H
NOP
NOP
NOP
110
SH79F642B
8.11 Warm-up Timer
8.11.1 Features
Built-in power on warm-up counter to eliminate unstable state of power on
Built-in oscillator warm-up counter to eliminate unstable state when oscillation startup
SH79F642B has a built-in power warm-up counter; it is designed to eliminate unstable state after power on or to do some
internal initial operation such as read customer option etc.
SH79F642B has also a built-in oscillator warm-up counter, it is designed to eliminate unstable state when oscillator starts
oscillating in the following conditions: Power-on reset, Pin reset, LVR reset, Watchdog Reset and Wake up from Power-down
mode.
After power-on, SH79F642B will start power warm-up procedure first, and then oscillator warm-up procedure.
Table 8.71 Power Warm-up Time
111
SH79F642B
8.12 Code Option
OP_WDT[7]:
0: disable watchdog (WDT) fuction(default)
1: enable watchdog (WDT) fuction
OP_WDTPD[6]:
0: disable watchdog fuction in Power-down mode
1: enable watchdog fuction in Power-down mode
OP_WDTSIDL[5]:
0: disable watchdog fuction in Super-IDLE mode
1: enable watchdog fuction in Super-IDLE mode
OP_LVREN[4]
0: disable Low Voltage Reset (LVR) fuction(default)
1: enable Low Voltage Reset (LVR) fuction
OP_RST[3]
0: P2.0 as RST pin(default)
1: P2.0 as I/O pin
OP_VIN[2]
0: P2.3 as VIN pin (default), VIN pin voltage detection function is enabled
1: P2.3 as I/O pin or AN0, VIN pin voltage detection function is disabled
112
SH79F642B
9. Energy Metering
9.1 Features
SH79F642 provides all the features that single-phase energy metering needed, including active power and active energy,
reactive power and reactive power, apparent power and apparent energy, voltage/ current RMS and frequency calculation to
support flexible anti-tampering program and calibration program.
Active energy error less than 0.1% in the dynamic range of 2000:1.
Reactive energy error less than 0.5% in the dynamic range of 1000:1.
Voltage/ Current RMS
Voltage frequency measurement
Pulse output PF/QF
Zero-corss and voltage sag interrupt detection
Supports software control pulse output
Supports single phase, 3 wire service
SH79F642 energy metering unit (EMU) is composed of the analog front-end (AFE) and digital signal processor (DSP). The
analog front-end acquisition two current signal and one voltage signal, the digital signal processor to complete the metering
function of the active power and active energy, reactive power and reactive energy, voltage rms, current rms and frequency
calculation. By the SFR registers and interrupt mode, the digital signal processing part can config calibration parameters and
read metering parameters.The PF/QF pin output the result of metering (Calibration pulse output) can be connected directly to
the standard meter to contrast error. EMU clock isselectable.
113
SH79F642B
9.4 Register
EMU, including two types of registers, one is SFR registers, the direct register, accessed by SFR address directly; the other is
metering parameters and calibration parameter register, indirect register, indirectly accessed by direct register
114
SH79F642B
Reset value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
115
SH79F642B
9.4.2 Indirect Register
The indirect registers include metering parameter registers and calibration parameter registers
All metering parameter registers are read-only but FREQ which can only be read by the EADR EDTAH / EDTAM / EDTAL
register indirect
1. EDTAH / EDTAM / EDTAL are stored 3 bytes of high, mid, low byte data if the metering parameter register is a 3-byte
register.
2. EDTAM / EDTAL are stored 2 bytes of mid, low byte data, and EDTAH is sign-extension bit of EDTM.7, if the metering
parameter register is a 2-byte register
Operating rules of metering parameters: first,write the accessed register address to EADR, read/ write flag is 0, then the
metering data of corresponding address update to the SFR registers EDTAH / EDTAM / EDTAL,finally, access EDTAH /
EDTAM / EDTAL register
As the same, calibration parameter configuration registers are read through the EADR EDTAM / EDTAL register indirectly,
but EDTAH register invalid
1. EDTAM and EDTAL are high and low bytes data of calibration parameter configuration register, if the parameter
configuration register is a 2-byte register.
2. EDTAL is the data of calibration parameter configuration register and EDTAM data is invalid, if the parameter
configuration register is a single-byte register.
Operating rules of calibration parameters
1. To access parameter configuration registers, first, write the accessed register address to EADR, read/ write flag is 0,
then the calibration parameter data of corresponding address update to the SFR registers EDTAM / EDTAL, finally, access
EDTAM / EDTAL register.
2. To write the calibration parameter configuration registers, first, write data to EDTAM / EDTAL, then, write the accessed
register address to EADR, read/ write flag is 1, then, the data of EDTAM / EDTAL registers update to calibration parameter
configuration registers of corresponding address.
Note: As the internal of EMU indirect register using a separate mechanism to read and writ, except this order, several NOP
need to be inserted after the EADR register read and write commands, then operate EDATH, EDATM, EDATL, more than 3
NOP need to be inserted when the system clock is 8.192MHz.
Metering Parameter Register
Table 9.7 EMU Metering Parameter Register list
Addresss Name Length Description
00H I1DTA 3 ADC output value of current channel 1
01H I2DTA 3 ADC output value of current channel 2
02H VDTA 3 ADC output value of voltage channel
03H APWR1 3 Active power value channel 1
04H RPWR1 3 Reactive power value channel 1
05H APWR2 3 Active power value channel 2
06H RPWR2 3 Reactive power value channel 2
07H AERY 3 Active energy value(CmodeFreq[2]=0)
08H RERY 3 Reactive energy value(CmodeFreq[2]=0)
09H FREQ 2 Voltage frequency value
0AH I1Rms 3 Current rms of channel 1
0BH I2Rms 3 Current rms of channel 2
0CH VRMS 3 Voltage rms
116
SH79F642B
0FH APWRA1 3 Active power average value of channel 1
10H RPWRA1 3 Reactive power average value of channel 1
11H APWRA2 3 Active power average value of channel 2
12H RPWRA2 3 Reactive power average value of channel 2
13H AERYL 3 Active energy low value (CmodeFreq[2]=0)
14H RERYL 3 Reactive energy low value (CmodeFreq[2]=0)
117
SH79F642B
Table 9.10 ADC Output of Voltage Channel
02H Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
VDTA VDTA.23 VDTA.22 VDTA.21 VDTA.20…3 VDTA.2 VDTA.1 VDTA.0
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
118
SH79F642B
Table 9.13 Active Power Value Channel 2 Register
05H Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
APWR2 APWR2.23 APWR2.22 APWR2.21 APWR2.20… APWR2.2 APWR2.1 APWR2.0
3
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
119
SH79F642B
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
120
SH79F642B
0CH Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
VRMS VRMS.23 VRMS.22 VRMS.21 VRMS.20…3 VRMS.2 VRMS.1 VRMS.0
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
121
SH79F642B
Active power average value of channel 1,the binary complement means a signed
23-0 APWR1[23:0] value,the cycle of measurement is set by SUMSAMPS.
Note:The positive number is active power of positive;Negative represent active power
negative.
122
SH79F642B
Table 9.27 Active energy low value (CmodeFreq[2]=0)
13H Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
AERYL AERYL.23 AERYL.22 AERYL.21 AERYL.20…3 AERYL.2 AERYL.1 AERYL.0
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
Table 9.30 Active energy accumulated value (high) in CONST mode (CmodeFreq[2]=1)
16H Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
AERY_CONS AERY_CONS AERY_CONS AERY_CONS AERY_CONS AERY_CONS AERY_CONS
AERY_CONSTH
TH.23 TH.22 TH.21 TH.20…3 TH.2 TH.1 TH.0
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
123
SH79F642B
Bit Number Bit Mnemonic Description
Active energy accumulated value (high) in CONST mode,the binary
23-0 AERY_CONSTH[23:0]
complement means a signed value
Table 9.31 Reactive energy accumulated value (high) in CONST mode (CmodeFreq[2]=1)
17H Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
RERY_CON RERY_CON RERY_CON RERY_CON RERY_CON RERY_CON RERY_CON
RERY_CONSTH
STH.23 STH.22 STH.21 STH.20…3 STH.2 STH.1 STH.0
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
Table 9.32 Active energy accumulated value (low) in CONST mode (CmodeFreq[2]=1)
18H Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
AERY_CONS AERY_CONS AERY_CONS AERY_CONS AERY_CONS AERY_CONS AERY_CONS
AERY_CONSTL
TL.23 TL.22 TL.21 TL.20…3 TL.2 TL.1 TL.0
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
Table 9.33 Reactive energy accumulated value (low) in CONST mode (CmodeFreq[2]=1)
19H Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
RERY_CON RERY_CON RERY_CON RERY_CON RERY_CON RERY_CON RERY_CON
RERY_CONSTL
STL.23 STL.22 STL.21 STL.20…3 STL.2 STL.1 STL.0
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
124
SH79F642B
Table 9.34 Active energy pulse accumulated value in CONST mode (CmodeFreq[2]=1)
1AH Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
WPA_CONS WPA_CONS WPA_CONS WPA_CONS WPA_CONS WPA_CONS WPA_CONS
WPA_CONST
T.23 T.22 T.21 T.20…3 T.2 T.1 T.0
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
Table 9.35 Reactive energy pulse accumulated value in CONST mode (CmodeFreq[2]=1)
19H Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
VARPA_CON VARPA_CON VARPA_CON VARPA_CON VARPA_CON VARPA_CON VARPA_CON
VARPA_CONST
ST.23 ST.22 ST.21 ST.20…3 ST.2 ST.1 ST.0
W/R R R R R R R R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
125
SH79F642B
126
SH79F642B
Reset value 0 0 0 0 0 0 0 0
u u u u u u u u
(POR/WDT/LVR/
0 0 0 0 0 0 0 0
PIN)
0 0 0 0 0 0 0 0
127
SH79F642B
CmodeFre CmodeFre CmodeFre ConstMod
EMUCFG1 QRUN PRUN PWRSEL1 PWRSEL0
q2 q1 q0 e
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset value 0 0 0 0 0 0 0 0
u u u u u u u u
(POR/WDT/LVR/
0 0 0 0 0 0 0 0
PIN)
0 0 0 0 0 0 0 0
128
SH79F642B
Accumulation Clock Frequency and Accumulation Data source select
000: Accumulation Clock Frequency: 2 X update frequency, accumulation data source:
instant power value ( selected by PWMSEL[1:0])
001: Accumulation Clock Frequency: 4 X update frequency, accumulation data source:
instant power value ( selected by PWMSEL[1:0])
010: Accumulation Clock Frequency: 8 X update frequency, accumulation data source:
instant power value ( selected by PWMSEL[1:0])
011: Accumulation Clock Frequency: 16 X update frequency, accumulation data
3-1 CmodeFreq[2:0] source: instant power value ( selected by PWMSEL[1:0])
100: Accumulation Clock Frequency: 32.768KHz, accumulation data source:
PCONST/RPCONST
101: Accumulation Clock Frequency: 8.192KHz, accumulation data source:
PCONST/RPCONST
110: Accumulation Clock Frequency: 4.096KHz, accumulation data source:
PCONST/RPCONST
111: Accumulation Clock Frequency: 1.024KHz, accumulation data source:
PCONST/RPCONST
Accumulation Module Enable
0 Cmodeen 0: Disable (init)
1: Enable
129
SH79F642B
PGA’S Chop Clock Select
000:2K
001:4K
010:8K
23-21 PGACHOPCKSEL[2:0] 011:16K
100:32K
101:64K
others:no clock
20-18 APGAUI[2:0] ADC bias current adjust of voltage channel
17-15 APGAI2I[2:0] ADC bias current adjust of current channel 1
14-12 APGAI1I[2:0] ADC bias current adjust of current channel 2
11-8 ADCUI[3:0] PGA bias current adjust of voltage channel
7-4 ADCI1[3:0] PGA bias current adjust of current channel 1
3-0 ADCI2[3:0] PGA bias current adjust of current channel 2
130
SH79F642B
15-0 EMUCFG3[15-0] EMU configuration parameter register 3. Typical value is 0x00E8
131
SH79F642B
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
132
SH79F642B
This register participate in the active power and energy calculation of channel 1.
Table 9.47 Active power offset of Channel 2
3AH Bit15 Bit14 Bit13 Bit12~Bit3 Bit2 Bit1 Bit0
WATT2OS W2OS.15 W2OS.14 W2OS.13 W2OS.12…3 W2OS.2 W2OS.1 W2OS.0
W/R W/R W/R W/R W/R W/R W/R W/R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
133
SH79F642B
W/R W/R W/R W/R W/R W/R W/R W/R
0 0 0 0000000 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0000000 0 0 0
0 0 0 0000000 0 0 0
IRMS2OS22
IRMS2OS IRMS2OS.23 IRMS2OS.10 IRMS2OS.9…3 IRMS2OS.2 IRMS2OS.1 IRMS2OS.0
….11
134
SH79F642B
Reset value 0 0 0 0 0 0 0
u u u u u u u
(POR/WDT/LVR/
0 0 0 0 0 0 0
PIN)
0 0 0 0 0 0 0
135
SH79F642B
VCONST VCONST.15 VCONST.14 VCONST.13 VCONST.12…3 VCONST.2 VCONST.1 VCONST.0
W/R W/R W/R W/R W/R W/R W/R W/R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
136
SH79F642B
0 0 0 0 1 0 0 0
Reset value u u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 0
137
SH79F642B
Table 9.64 Active power const register
4BH Bit23 Bit22 Bit21 Bit20~Bit3 Bit2 Bit1 Bit0
APCONST APCST.23 APCST.22 APCST.21 APCST.20…3 APCST.2 APCST.1 APCST.0
W/R W/R W/R W/R W/R W/R W/R W/R
0 0 0 0 0 0 0
Reset value u u u u u u u
(POR/WDT/LVR/PIN) 0 0 0 0 0 0 0
0 0 0 0 0 0 0
138
SH79F642B
9.5 Metering Function Description
EMU metering of active power, active energy, reactive power, reactive energy, voltage rms, current rms, corresponding
correction function.
9.5.1 Active Power, Reactive Power
The voltage multiplied the current, and passed the low pass filter, then multiplied by the correction gain, the active power is
achieved and stored to the register APWR1/APWR2. The high bit of W1GAIN and W2GAIN is sign bit, and correction gain is
1+W1GAIN/216. The correction gain range of -0.5~1.5.
P1CAL LPFINDEX
W1GAIN
⊕
I1P +
ADC I1DTA Φ
⊗ ⊗ ⊕
I1N -
PGA APWR1 ∑ APWRA1
ADCOSI1
LPFINDEX
SUMSAMPS
WATT1OS
⊕
VP +
ADC VDTA
VN - Q1GAIN
PGA
ADCOSV
P2CAL LPFINDEX
π
⊗ ⊗ ⊕ RPWR1 ∑ RPWRA1
⊕
I2P + 2
ADC SUMSAMPS
I2N - I2DTA Φ
VAR1OS
PGA
ADCOSI2 Q2GAIN
⊗ ⊗ ⊕ RPWR2 ∑ RPWRA2
SUMSAMPS
VAR2OS
W2GAIN
⊗ ⊗ ⊕ APWR2 ∑ APWRA2
SUMSAMPS
WATT2OS
X2 ⊕ ∑ VRMS
VRMSOS SUMSAMPS
X 2
⊕ ∑ ⊗ IRMS2
X2 ⊕ ∑ IRMS1
IRM1OS SUMSAMPS
The active ( reactive ) power average value is calculated by a cycle time which set by SUMSAMPS register. The same to
voltage RMS and current RMS value.
9.5.2 Energy and Pulse Output
The internal active energy register of 48bits, the highest bit is sign bit, to accumulate active power.The active energy value
register (AERY) is high 24 bits of the internal active energy register, and the value back to 0 after overflowed.
The internal reactive energy register of 48bits, the highest bit is sign bit, to accumulate reactive power.The reactive energy
value register (RERY) is high 24 bits of the internal reactive energy register, and the value back to 0 after overflowed.
By the conversion of the active and reactive energy, the corresponding proportion pulse output from PF and QF pin.
The energy can select 3 cumulative mode of forward, absolute value and algebraic sum metering through the QMOD and
PMOD of EMCON.
There are two source of energy accumulation, one is active power value of present metering channel, the other is the const
value which store in PCONST/RPCONST.
139
SH79F642B
APWR
∑
AERY[23:0]
PCONT +
AERYL[23:0]
PF
PCONST -
ICONT
RPWR +
QF
∑
RERY[23:0]
QCONT -
RERYL[24:0]
RPCONST
The active energy accumulating, the fast active pulse register PCNT increase 1LSB when the 23 bit (least significant bit to
0) of the internal active energy register increase 1, and if the absolute value of the register is greater than or euqal to the the
value of ouput pulse frequence configuration register, outputing an active pulse of PF, setting PFIF(EMUIF.3) to 1, and the
corresponding energy pulse accumulated register plus 1, the absolute active energy pulse accumulated register plus 1, clear
REVP flag.
The active energy accumulating, the fast active pulse register PCNT decrease 1LSB when the 23 bit (least significant bit to
0) of the internal active energy register decrease 1, and if the absolute value of the register is greater than or euqal to the the
value of ouput pulse frequence configuration register, outputing an active pulse of PF, setting PFIF(EMUIF.3) to 1, and the
corresponding energy pulse accumulated register plus 1, the absolute active energy pulse accumulated register plus 1, set
REVP flag to 1.
The reactive energy accumulating, the fast reactive pulse register QCNT increase 1LSB when the 23 bit (least significant
bit to 0) of the internal reactive energy register increase 1, and if the absolute value of the register is greater than or euqal to the
the value of ouput pulse frequence configuration register, outputing an reactive pulse of QF, setting QFIF(EMUIF.4) to 1, and
the corresponding energy pulse accumulated register plus 1. the absolute reactive energy pulse accumulated register plus 1,
clear REVQ flag.
The reactive energy accumulating, the fast reactive pulse register QCNT decrease 1LSB when the 23 bit (least significant
bit to 0) of the internal reactive energy register decrease 1, and if the absolute value of the register is greater than or euqal to the
the value of ouput pulse frequence configuration register, outputing an reactive pulse of QF, setting QFIF(EMUIF.4) to 1, and
the corresponding energy pulse accumulated register plus 1. the absolute reactive energy pulse accumulated register plus 1,
set REVQ flag to 1.
The reverse of active and reactive energy can be indicated by the REVP and RECQ of the status/control register EMUSR.
When active pulse output, update REVP, and update REVQ when reactive pulse output.
The NoQld and NoPld of EMUSR could display the state of energy startup in real time, and the threshold selection will be
easier.
140
SH79F642B
9.5.3 No Neutral Wire Mode
If the no neutral wire mode is enabled. Use the value in VCONST register ( instead of ADC sampling value of voltage
channel ) to calculate active/reactive power value.
9.5.4 MAX ADC Sampling Value Record of Voltage Channel
In a sampling period ( set by SAMSAMPS register), record the max ADC sampling absolute value of voltage channel and
update the value to VDTAMAX register.
Voltage
SUMSAMPS Vaveform VDTAMAX
monitor
⊕
V1P
ADC VDTA
V1N
ADCOSV
Sag Detect
ADC
⊕ VDTA
Zero crossing
detect
ADCOSV
141
SH79F642B
D6H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
EMUIE QFEN PFEN DSPIE QFIE PFIE SUMIE SAGIE ZXIE
W/R W/R W/R W/R W/R W/R W/R W/R W/R
Reset value
0 0 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
142
SH79F642B
Table 9.69 EMU interrupt request register
D7H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
EMUIF - - DSPIF QFIF PFIF SUMIF SAGIF ZXIF
W/R - - W/R W/R W/R W/R W/R W/R
Reset value
- - 0 0 0 0 0 0
(POR/WDT/LVR/PIN)
143
SH79F642B
10. Instruction Set
ARITHMETIC OPERATIONS
Opcode Description Code Byte Cycle
ADD A, Rn Add register to accumulator 0x28-0x2F 1 1
ADD A, direct Add direct byte to accumulator 0x25 2 2
ADD A, @Ri Add indirect RAM to accumulator 0x26-0x27 1 2
ADD A, #data Add immediate data to accumulator 0x24 2 2
Add register to accumulator with carry
ADDC A, Rn 0x38-0x3F 1 1
flag
ADDC A, direct Add direct byte to A with carry flag 0x35 2 2
ADDC A, @Ri Add indirect RAM to A with carry flag 0x36-0x37 1 2
ADDC A, #data Add immediate data to A with carry flag 0x34 2 2
SUBB A, Rn Subtract register from A with borrow 0x98-0x9F 1 1
SUBB A, direct Subtract direct byte from A with borrow 0x95 2 2
SUBB A, @Ri Subtract indirect RAM from A with borrow 0x96-0x97 1 2
Subtract immediate data from A with
SUBB A, #data 0x94 2 2
borrow
INC A Increment accumulator 0x04 1 1
INC Rn Increment register 0x08-0x0F 1 2
INC direct Increment direct byte 0x05 2 3
INC @Ri Increment indirect RAM 0x06-0x07 1 3
DEC A Decrement accumulator 0x14 1 1
DEC Rn Decrement register 0x18-0x1F 1 2
DEC direct Decrement direct byte 0x15 2 3
DEC @Ri Decrement indirect RAM 0x16-0x17 1 3
INC DPTR Increment data pointer 0xA3 1 4
MUL AB 8X8 11
Multiply A and B 0xA4 1
16 X 8 20
DIV AB 8/8 11
Divide A by B 0x84 1
16 / 8 20
DA A Decimal adjust accumulator 0xD4 1 1
144
SH79F642B
LOGIC OPERATIONS
Opcode Description Code Byte Cycle
ANL A, Rn AND register to accumulator 0x58-0x5F 1 1
ANL A, direct AND direct byte to accumulator 0x55 2 2
ANL A, @Ri AND indirect RAM to accumulator 0x56-0x57 1 2
ANL A, #data AND immediate data to accumulator 0x54 2 2
ANL direct, A AND accumulator to direct byte 0x52 2 3
ANL direct, #data AND immediate data to direct byte 0x53 3 3
ORL A, Rn OR register to accumulator 0x48-0x4F 1 1
ORL A, direct OR direct byte to accumulator 0x45 2 2
ORL A, @Ri OR indirect RAM to accumulator 0x46-0x47 1 2
ORL A, #data OR immediate data to accumulator 0x44 2 2
ORL direct, A OR accumulator to direct byte 0x42 2 3
ORL direct, #data OR immediate data to direct byte 0x43 3 3
XRL A, Rn Exclusive OR register to accumulator 0x68-0x6F 1 1
XRL A, direct Exclusive OR direct byte to accumulator 0x65 2 2
XRL A, @Ri Exclusive OR indirect RAM to accumulator 0x66-0x67 1 2
Exclusive OR immediate data to
XRL A, #data 0x64 2 2
accumulator
XRL direct, A Exclusive OR accumulator to direct byte 0x62 2 3
XRL direct, #data Exclusive OR immediate data to direct byte 0x63 3 3
CLR A Clear accumulator 0xE4 1 1
CPL A Complement accumulator 0xF4 1 1
RL A Rotate accumulator left 0x23 1 1
RLC A Rotate accumulator left through carry 0x33 1 1
RR A Rotate accumulator right 0x03 1 1
RRC A Rotate accumulator right through carry 0x13 1 1
SWAP A Swap nibbles within the accumulator 0xC4 1 4
145
SH79F642B
DATA TRANSFERS
Opcode Description Code Byte Cycle
MOV A, Rn Move register to accumulator 0xE8-0xEF 1 1
MOV A, direct Move direct byte to accumulator 0xE5 2 2
MOV A, @Ri Move indirect RAM to accumulator 0xE6-0xE7 1 2
MOV A, #data Move immediate data to accumulator 0x74 2 2
MOV Rn, A Move accumulator to register 0xF8-0xFF 1 2
MOV Rn, direct Move direct byte to register 0xA8-0xAF 2 3
MOV Rn, #data Move immediate data to register 0x78-0x7F 2 2
MOV direct, A Move accumulator to direct byte 0xF5 2 2
MOV direct, Rn Move register to direct byte 0x88-0x8F 2 2
MOV direct1, direct2 Move direct byte to direct byte 0x85 3 3
MOV direct, @Ri Move indirect RAM to direct byte 0x86-0x87 2 3
MOV direct, #data Move immediate data to direct byte 0x75 3 3
MOV @Ri, A Move accumulator to indirect RAM 0xF6-0xF7 1 2
MOV @Ri, direct Move direct byte to indirect RAM 0xA6-0xA7 2 3
MOV @Ri, #data Move immediate data to indirect RAM 0x76-0x77 2 2
MOV DPTR, #data16 Load data pointer with a 16-bit constant 0x90 3 3
MOVC A, @A+DPTR Move code byte relative to DPTR to A 0x93 1 7
MOVC A, @A+PC Move code byte relative to PC to A 0x83 1 8
MOVX A, @Ri Move external RAM (8-bit address) to A 0xE2-0xE3 1 5
MOVX A, @DPTR Move external RAM (16-bit address) to A 0xE0 1 6
MOVX @Ri, A Move A to external RAM (8-bit address) 0xF2-F3 1 4
MOVX @DPTR, A Move A to external RAM (16-bit address) 0xF0 1 5
PUSH direct Push direct byte onto stack 0xC0 2 5
POP direct Pop direct byte from stack 0xD0 2 4
XCH A, Rn Exchange register with accumulator 0xC8-0xCF 1 3
XCH A, direct Exchange direct byte with accumulator 0xC5 2 4
XCH A, @Ri Exchange indirect RAM with accumulator 0xC6-0xC7 1 4
Exchange low-order nibble indirect RAM
XCHD A, @Ri 0xD6-0xD7 1 4
with A
146
SH79F642B
PROGRAM BRANCHES
Opcode Description Code Byte Cycle
ACALL addr11 Absolute subroutine call 0x11-0xF1 2 7
LCALL addr16 Long subroutine call 0x12 3 7
RET Return from subroutine 0x22 1 8
RETI Return from interrupt 0x32 1 8
AJMP addr11 Absolute jump 0x01-0xE1 2 4
LJMP addr16 Long jump 0x02 3 5
SJMP rel Short jump (relative address) 0x80 2 4
JMP @A+DPTR Jump indirect relative to the DPTR 0x73 1 6
JZ rel (not taken) 3
Jump if accumulator is zero 0x60 2
(taken) 5
JNZ rel (not taken) 3
Jump if accumulator is not zero 0x70 2
(taken) 5
JC rel (not taken) 2
Jump if carry flag is set 0x40 2
(taken) 4
JNC rel (not taken) 2
Jump if carry flag is not set 0x50 2
(taken) 4
JB bit,rel (not taken) 4
Jump if direct bit is set 0x20 3
(taken) 6
JNB bit,rel (not taken) 4
Jump if direct bit is not set 0x30 3
(taken) 6
JBC bit, rel (not taken) 4
Jump if direct bit is set and clear bit 0x10 3
(taken) 6
CJNE A,direct,rel (not taken) Compare direct byte to A and jump if not 4
0xB5 3
(taken) equal 6
CJNE A,#data,rel (not taken) Compare immediate to A and jump if not 4
0xB4 3
(taken) equal 6
CJNE Rn,#data,rel (not taken) Compare immediate to reg. and jump if 4
0xB8-0xBF 3
(taken) not equal 6
CJNE @Ri,#data,rel (not taken) Compare immediate to Ri and jump if not 4
0xB6-0xB7 3
(taken) equal 6
DJNZ Rn,rel (not aken) 3
Decrement register and jump if not zero 0xD8-0xDF 2
(taken) 5
DJNZ direct,rel (not taken) Decrement direct byte and jump if not 4
0xD5 3
(taken) zero 6
NOP No operation 0 1 1
147
SH79F642B
BOOLEAN MANIPULATION
Opcode Description Code Byte Cycle
CLR C Clear carry flag 0xC3 1 1
CLR bit Clear direct bit 0xC2 2 3
SETB C Set carry flag 0xD3 1 1
SETB bit Set direct bit 0xD2 2 3
CPL C Complement carry flag 0xB3 1 1
CPL bit Complement direct bit 0xB2 2 3
ANL C, bit AND direct bit to carry flag 0x82 2 2
ANL C, /bit AND complement of direct bit to carry 0xB0 2 2
ORL C, bit OR direct bit to carry flag 0x72 2 2
ORL C, /bit OR complement of direct bit to carry 0xA0 2 2
MOV C, bit Move direct bit to carry flag 0xA2 2 2
MOV bit, C Move carry flag to direct bit 0x92 2 3
148
SH79F642B
11. Electrical Characteristics
Absolute Maximum Ratings
DC Supply Voltage. . . . . . . . . . . .. . . . . . . . . –0.3V to +3.8V * Comments
Input / Output Voltage. . . . . . . . DGND-0.3V to VOUT +0.3V Stresses exceed those listed under “Absolute Maximum
Ratings” may cause permanent damage to this device.
Analog input voltage.. . .. . . . . . . .AGND-0.3V to VDD +0.3V These are stress ratings only. Functional operation of this
device at these or any other conditions above those
Operating Ambient Temperature. . . . . . .. . .-40°C to +85°C indicated in the operational sections of this specification is
not implied or intended. Exposure to the absolute maximum
Store Temperature. . . . . . . . . . . . . . . . . . . .–55°C to +125°C rating conditions for extended periods may affect device
reliability.
FLASH Memory write / erase operations . . 0°C to +85°C
Electrical Characteristics (VDD = 3.0 – 3.6V, DGND = 0V, VBAT = 2.4 – 3.6V, TA = 25°C, unless otherwise specified)
Parameter Symbol Min. Typ. ∗ Max. Unit Condition
Operating Voltage VDD 2.2 3.3 3.6 V 32.768kHz ≤ fSYS ≤ 8.192MHz
Battery Voltage VBAT 2.2 3.3 3.8 V 32.768kHz ≤ fSYS ≤ 8.192MHz
fsys = Fsys/12, PLL on
All output pins unload(including all digital
Operating Current IOP2 - 1.4 mA input pins un-floating), CPU on (execute
NOP instruction), LCD on,WDT on , LVR
on, LPD on, EMU on, RTC on, disable other
fuctions, VDD =3.3V, VBAT=3.3V.
fsys = 32.768kHz, PLL off
All output pins unload(including all digital
Stand by Current (IDLE) ISB1 - 11 18 uA input pins un-floating)LCD off, WDT off,
LVR on, RTC on, LPD on, disable other
fuctions, VDD =3.3V, VBAT=3.3V.
fOSC = OFF, PLL off
All output pins unload(including all digital
Stand by Current
ISB2 - - 10 uA input pins un-floating), LCD off, RTC off,
(Power-Down)
WDT off, LVR on, disable other fuctions,
VDD =3.3V, VBAT=3.3V.
All output pins unload;watchdog on VDD
WDT Current IWDT - - 1 uA
=3.3V
LPD2 Current ILPD2 - - 4 uA -
PLL Current IPLL 350 380 µA -
Traditional LCD mode, VDD =3.3V
LCD Current 1 ILCD1 - 3 5 uA 900k LCD bias, contrast[2:0]=000
(Not include LCD panel)
LCD Fast charge mode, VDD =3.3V
900k LCD bias, 1/16 LCD com period,
LCD Current 2 ILCD2 - 7 9 uA
contrast[2:0]=111
(Not include LCD panel)
Input Low Voltage 1 VIL1 GND - 0.3 X VDD V I/O port
Input high Voltage 1 VIH1 0.7 X VDD - VDD V I/O port
————
Input Low Voltage 2 VIL2 GND - 0.2 X VDD V RST, T0, T1, T2, T2EX, INT0, INT1, INT2,
INT3 (Schmitt trigger)
149
SH79F642B
————
Input high Voltage 2 VIH2 0.8 X VDD - VDD V RST, T0, T1, T2, T2EX, INT0, INT1, INT2,
INT3 (Schmitt trigger)
Input Leakage Current IIL -1 1 uA No pull-high, VIN= VDD or DGND
Pull-high Resistor RPH1 - 50 - kΩ VDD =3.3V, VIN=DGND
I/O port, IOH = -3mA, VDD = 3.3V
Output High Voltage1 VOH1 VDD – 0.4 - - V
(not include P4,P5,P0.6,P0.7)
I/O port, IOL = 8mA, VDD = 3.3V
Output Low Voltage1 VOL1 - - GND + 0.5 V
(not include P4,P5,P0.6,P0.7)
150
SH79F642B
151
SH79F642B
152
SH79F642B
AC Electrical Characteristics (VOUT = 2.4V - 3.6V, DGND = 0V, TA = 25°C, fOSC = 32.768kHz, unless otherwise specified)
Parameter Symbol Min. Typ. ∗ Max. Unit Condition
Oscillator Start time TOSC - 1 2 s Oscillator = 32768Hz
PLL Start time TPLL - 2 - ms Does not include oscillator start-up
PLL jitter(Period) JPLL - 1 - ns -
RST pulse width tRESET 10 - - us Active-low
RESET pin Pull-high RRPH - 50 - kΩ VOUT = 3.3V, VIN = DGND
Resistor
Low Voltage Reset Electrical Characteristics (VOUT = 2.4V - 3.6V, DGND = 0V, TA = 25°C, unless otherwise specified)
Parameter Symbol Min. Typ. ∗ Max. Unit Condition
LVR voltage VLVRL 2.2 2.3 2.4 V LVR enabled,VOUT = 2.2V - 3.6V
153
SH79F642B
12. Ordering Information
Product ID Package
SH79F642BP/064PR LQFP64(10*10)
SH79F642BS/064SR LQFP64(7*7)
SH79F6421S/064SR LQFP64(7*7)
154
SH79F642B
13. Package Information
LQFP64 (BODY SIZE: 10*10) Unit: inch / mm
HD
D
64 49
1 48
HE
E
16 33
17 e b 32
c
A2
A
A1
See Detail F
L
Seating Plane
L1
DETAIL F
155
SH79F642B
LQFP64 Outline Dimensions (BODY SIZE: 7×7) Unit: inch / mm
HD
64 49
1 48
HE
E
16 33
17 e b 32
c
A2
A
A1
See Detail F
L
L1
DETAIL F
156
SH79F642B
15. Datasheet Document History
157