Nuvoton-N76E003
The article was written by MEIGROUP engineers
Project using Nuvoton-N76E003 8051 and library TM1637 Display, I2C EEPROM AT24Cx 24LCx , pinMode like arduino, Modbus send data emulator....
Instructions and sample program
__ Standard library __ (Standard libraries)
Standard libraries are called in all projects
__ Data type 8051 __ (data type)
- In addition to common data types, KeilC-8051 also has a number of other data types and memory organizations
bit var; // size: 1 bit - similar to bool, only has 2 values 0 and 1
xdata dataType var; // 'xdata' - is a keyword used to specify that the variable should be stored
// in peripheral memory instead of being stored in main memory.
// Helps free up main memory for important tasks
bit var1bit;
xdata int varInt;
xdata float varFloat;
__ Some default command __ (some default commands)
GPIO
- GPIO mode
- GPIO set
- GPIO read status
UART
- Example UART
Timer delay __ Built-in delay functions
__ USE Library __ (use self-created library)
Download folder LIB, save to package folder.
Open project in keilC, go to Options for Target -> tab C51, add "..\..\LIB" to Include Paths
_ GPIO Setup _ (using self-made "GPIO.h" library)
USE library LIB\GPIO.h __ Use GPIO.h library
- Config gpio
P12output,P04input,P05Open drain mode:
Mode | Description |
|---|---|
QUASI | Config gpio quasi mode __ (set gpio as input and output, output high-low logic level, receive input signal) |
OUTPUT | Config gpio push-pull mode __ (output logic high-low) |
INPUT | Config gpio input only mode __ (as input only) |
INPUT_OD | Config gpio input Open-drain mode __ (output low level logic and receive input signal) |
_ digital-Write-Read (LIB\GPIO.h) _ read and write digital signals
- Set output gpio
P15toHIGH, gpioP05toLOW
- Reads the value from digital pin
P11,P03
_ analogRead (LIB\GPIO.h) _ reads the ADC gpio signal
N76E003 has 8 gpios that can read ADC signals as gpio pins
AINx(x = 0 -> 7)Read analog value from gpio P11
Create 2 functions Serial.read() and Serial.available() like arduino
set up Timer2 interrupt __ creates Timer2 interrupt 1kHz (used as millis() on arduino)
Timer 2 is a 16 bit count down timer (65536 -> 0)
To set up a 1khz timer interrupt, we calculate as follows:
- Setup CLK divider (1, 4, 16, 32, 64, 128, 256, 512): Ftimer = FCLK_SYS / DIV
- Set autoReload mode for timer2
- Calculate the reload value and place it in the reload register
- counter = period (s) * 1,000,000
- reload_value = 65536 - (Ftimer * counter)
- Put into reload register and Enable run timer
- The interrupt event will be placed in the function
Timer2_ISRlike the example below
Read and write EEPROM - Use library LIB\I2Ceeprom.h
Reference from the article MS51FB9AE – I2C
- Includes 2 libraries
I2Ceeprom.hused for eeprom ICs with 1k, 2k bits [AT24C01, AT24C02]I2Ceeprom2.hused for other eeprom ICs with larger memory [AT24C04, AT24C08, AT24C16, 32, ...]- Functions will return
1If read, write data successfully and return0when it fails
Functions are created






