MikroElektronika white logo
  • Products
    • Click Boards
      • Wireless Connectivity
        • GPS/GNSS
        • GSM/LTE
        • LTE IoT
        • BT/BLE
        • WiFi
        • RFID/NFC
        • GSM+GPS
        • 6LoWPAN
        • ZigBee
        • UWB
        • SigFox
        • Sub-1 GHz Transceievers
        • 2.4 GHz Trancevers
        • LoRa
        • WiFi+BLE
      • Sensors
        • Biometrics
        • Gas
        • Magnetic
        • Motion
        • Optical
        • Pressure
        • Proximity
        • Temperature & humidity
        • Current sensor
        • Miscellaneous
        • Environmental
        • Force
        • Inductance
        • RF meter
        • Click Shields
        • Click Bundles
      • Interface
        • Adapter
        • CAN
        • Port expander
        • RS485
        • USB
        • 1-Wire
        • RS232
        • Ethernet
        • LIN
        • PWM
        • Current
        • DALI
        • I2C
        • Fiber optics
        • SPI
        • DMX
        • CXPI
        • Click Shields
        • Click Bundles
      • Display & LED
        • LED Drivers
        • LED Matrix
        • LED Segment
        • OLED
        • LCD
        • TFT
        • Click Shields
        • Click Bundles
      • Miscellaneous
        • Relay
        • Optocoupler
        • ID
        • Proto
        • Encryption
        • Click Shields
        • Click Bundles
      • Mixed Signal
        • ADC
        • Measurements
        • DAC
        • Digital potentiometer
        • ADC-DAC
        • Click Shields
        • Click Bundles
      • Storage
        • EEPROM
        • FLASH
        • FRAM
        • microSD
        • MRAM
        • SRAM
        • EERAM
        • ReRAM
        • DRAM
        • Click Shields
        • Click Bundles
      • Motor Control
        • Brushed
        • Brushless
        • Servo
        • Stepper
        • Click Shields
        • Click Bundles
      • Audio & Voice
        • Amplifier
        • Microphone
        • Speakers
        • Signal Processing
        • Speech recognition
        • FM
        • MP3
        • Click Shields
        • Click Bundles
      • HMI
        • Capacitive
        • Pushbutton/Switches
        • Potentiometers
        • Rotary encoder
        • Haptic
        • Fingerprint
        • Click Shields
        • Click Bundles
      • Clock & Timing
        • RTC
        • Clock generator
        • Click Shields
        • Click Bundles
      • Power Management
        • Battery charger
        • Boost
        • Buck
        • Linear
        • Buck-Boost
        • Wireless Charging
        • Power Switch
        • USB-C PD
        • Click Shields
        • Click Bundles
      • Click Bundles
      • Click Shields
    • NECTO
      • NECTO Studio
    • Compilers
      • PIC
        • C
          • NECTO Studio
          • mikroC PRO for PIC
        • Basic
          • mikroBasic PRO for PIC
        • Pascal
          • mikroPascal PRO for PIC
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual TFT AI
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • dsPIC/PIC24
        • C
          • NECTO Studio
          • mikroC PRO for dsPIC
        • Basic
          • mikroBasic PRO for dsPIC
        • Pascal
          • mikroPascal PRO for dsPIC
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • PIC32
        • C
          • NECTO Studio
          • mikroC PRO for PIC32
        • Basic
          • mikroBasic PRO for PIC32
        • Pascal
          • mikroPascal PRO for PIC32
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • ARM
        • C
          • NECTO Studio
          • mikroC PRO for ARM
        • Basic
          • mikroBasic PRO for ARM
        • Pascal
          • mikroPascal PRO for ARM
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual TFT AI
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • AVR
        • C
          • NECTO Studio
          • mikroC PRO for AVR
        • Basic
          • mikroBasic PRO for AVR
        • Pascal
          • mikroPascal PRO for AVR
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • FT90x
        • C
          • mikroC PRO for FT90x
        • Basic
          • mikroBasic PRO for FT90x
        • Pascal
          • mikroPascal PRO for FT90x
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • 8051
        • C
          • mikroC PRO for 8051
        • Basic
          • mikroBasic PRO for 8051
        • Pascal
          • mikroPascal PRO for 8051
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
    • Dev Boards
      • PIC (8-bit)
        • 8th Generation
          • Fusion for PIC v8
          • EasyPIC PRO v8
          • EasyPIC PRO v8 over USB-C
          • EasyPIC v8
          • EasyPIC v8 over USB-C
          • UNI-DS v8
          • UNI-DS v8 over USB-C
        • 7th Generation
          • EasyPIC PRO v7a
          • PICPLC16 v7a
          • EasyPIC v7a
          • EasyPIC PRO v7
          • EasyPIC v7
        • 6th Generation
          • PICPLC16 v6
      • dsPIC/PIC24 (16-bit)
        • 8th Generation
          • EasyPIC v8 PIC24/dsPIC33
          • EasyPIC v8 for dsPIC30
          • EasyPIC v8 for dsPIC30 over USB-C
          • Fusion for PIC v8
          • UNI-DS v8
          • UNI-DS v8 over USB-C
        • 7th Generation
          • EasyPIC Fusion v7
          • EasyPIC v7 for dsPIC30
        • 6th Generation
          • Easy24-33 v6
      • PIC32 (32-bit)
        • 8th Generation
          • Fusion for PIC32
          • Fusion for PIC32 over USB-C
          • Fusion for PIC v8
          • UNI-DS v8
          • UNI-DS v8 over USB-C
        • 7th Generation
          • EasyPIC Fusion v7
      • ARM (32-bit)
        • 8th Generation
          • Fusion for ARM v8
          • Fusion for ARM v8 over USB-C
          • Fusion for STM32 v8
          • Fusion for STM32 over USB-C
          • Fusion for KINETIS v8
          • Fusion for Kinetis v8 over USB-C
          • Fusion for TIVA v8
          • Fusion for TIVA v8 over USB-C
          • UNI-DS v8
          • UNI-DS v8 over USB-C
        • 7th Generation
          • EasyMx PRO v7a STM32
          • EasyMx PRO v7 STM32
          • EasyMx PRO v7 Tiva
      • AVR (8-bit)
        • 8th Generation
          • EasyAVR v8
          • EasyAVR PRO v8
          • EasyAVR PRO v8 over USB-C
          • UNI-DS v8
          • UNI-DS v8 over USB-C
        • 7th Generation
          • EasyAVR v7
        • 6th Generation
          • AVRPLC16 v6
      • 8051 (8-bit)
        • 7th generation
          • BIG8051
        • 6th Generation
          • Easy8051 v6
      • PSoC (8-bit)
        • 6th Generation
          • UNI-DS6 Development System
      • RISC-V (32bit)
        • 8th Generation
          • UNI-DS v8
          • UNI-DS v8 over USB-C
      • Universal Boards
        • 8th Generation
          • UNI-DS v8
          • UNI-DS v8 over USB-C
          • Fusion for PIC v8
          • Fusion for ARM v8
        • 7th Generation
          • EasyPIC Fusion v7
        • 6th Generation
          • UNI-DS6
          • mikroBoard for PIC 80-pin
          • mikroBoard for AVR
          • mikroBoard for dsPIC
          • mikroBoard for PSoC
          • mikroBoard for 8051
          • mikroBoard for PIC 40-pin
          • mikroBoard for ARM
          • mikroBoard for ARM 144-pin
      • IoT - Wearable
        • Hexiwear
          • Hexiwear
          • Hexiwear Power User Pack
          • Hexiwear Docking Station
          • Hexiwear Battery Pack
          • Hexiwear Color Pack
          • Hexiwear Workstation
      • Analog Boards
        • 7th Generation
          • Analog System Lab Kit PRO
    • Starter Boards
      • PIC (8-bit)
        • Clicker
          • PIC clicker
        • Clicker 2
          • Clicker 2 for PIC18FJ
          • Clicker 2 for PIC18FK
        • Clicker 4
          • Clicker 4 for PIC18F
          • UNI Clicker
        • Ready
          • Ready for PIC Board
          • Ready for PIC (DIP28)
          • PIC-Ready2 Board
          • MMC Ready Board
        • StartUSB
          • StartUSB for PIC
      • dsPIC/PIC24 (16-bit)
        • Clicker 2
          • Clicker 2 for PIC24
          • Clicker 2 for dsPIC33
        • Clicker 4
          • UNI Clicker
        • Ready
          • dsPIC-Ready1 Board
          • dsPIC-Ready2 Board
          • DsPIC-Ready3 Board
          • dsPIC-Ready4 Board
      • PIC32 (32-bit)
        • Clicker
          • PIC32MX clicker
          • 6LoWPAN Clicker
          • PIC32MZ clicker
        • Clicker 2
          • Clicker 2 for PIC32MX
          • Clicker 2 for PIC32MZ
        • Clicker 4
          • UNI Clicker
        • MINI
          • MINI-32 Board
          • MINI-32 for PIC32MZ
        • Flip&Click
          • Flip&Click PIC32MZ
      • ARM (32-bit)
        • Clicker
          • RA4M1 Clicker
          • Kinetis Clicker
          • MSP432 Clicker
          • CEC1702 clicker
          • CEC1302 Clicker
          • STM32 M4 clicker
        • Clicker 2
          • Clicker 2 for STM32
          • Clicker 2 for Kinetis
          • Clicker 2 for CEC1702
          • Clicker 2 for MSP432
          • Clicker 2 for CEC1302
          • Clicker 2 for PSoC 6
        • Clicker 4
          • Clicker 4 for STM32F745VG
          • Clicker 4 for STM32F4
          • Clicker 4 for TMPM3H
          • Clicker 4 for TMPM4K
          • Clicker 4 for STM32
          • UNI Clicker
        • MINI
          • MINI-M4 for STM32
          • MINI-M4 For Kinetis
          • MINI-M4 for Tiva
          • MINI-M4 for Stellaris
          • MINI-M4 for MSP432
          • MINI-M0 for STM32
        • Flip&Click
          • Flip&Click SAM3X
      • AVR (8-bit)
        • Clicker 4
          • UNI Clicker
        • MINI
          • MINI-AT Board - 3.3V
          • MINI-AT Board - 5V
        • Ready
          • Ready for AVR Board
          • Ready For XMEGA
          • mikroXMEGA Board
          • AVR-Ready2 Board
        • StartUSB
          • StartUSB for AVR
      • 8051 (8-bit)
        • Ready
          • 8051-Ready Board
      • FT90x (32-bit)
        • Clicker 2
          • Clicker 2 for FT90x
      • Miscellaneous
        • USB
          • USB Wizard
          • Quail
          • FlowPaw Kit
      • Universal Boards
        • Clicker 4
          • UNI Clicker
    • Prog-Debug
      • PIC (8-bit)
        • CODEGRIP
          • UNI CODEGRIP
          • UNI CODEGRIP - USB-C
          • CODEGRIP for PIC
          • CODEGRIP for PIC USB-C
        • mikroProg
          • mikroProg for PIC
      • dsPIC/PIC24 (16-bit)
        • CODEGRIP
          • UNI CODEGRIP
          • UNI CODEGRIP - USB-C
          • CODEGRIP for PIC
        • mikroProg
          • mikroProg for dsPIC
      • PIC32 (32-bit)
        • CODEGRIP
          • UNI CODEGRIP
          • UNI CODEGRIP - USB-C
          • CODEGRIP for PIC
          • CODEGRIP for PIC USB-C
        • mikroProg
          • mikroProg for PIC32
      • ARM (32-bit)
        • CODEGRIP
          • UNI CODEGRIP
          • UNI CODEGRIP USB-C
          • CODEGRIP for ARM
          • CODEGRIP for ARM USB-C
          • CODEGRIP for STM32
          • CODEGRIP for KINETIS
          • CODEGRIP for Tiva
          • CODEGRIP for Tiva USB-C
        • mikroProg
          • mikroProg for STM32
          • mikroProg for Tiva
          • mikroProg for Kinetis
          • mikroProg for CEC
          • mikroProg for MSP432
          • mikroProg for PSoC 5LP
      • AVR (8-bit)
        • CODEGRIP
          • CODEGRIP for AVR
          • CODEGRIP for AVR - USB-C
          • UNI CODEGRIP
          • UNI CODEGRIP - USB-C
        • mikroProg
          • mikroProg for AVR
      • 8051 (8-bit)
        • mikroProg
          • mikroProg for 8051
      • FT90x (32-bit)
        • mikroProg
          • mikroProg for FT90x
    • Smart Displays
      • 2.8"
        • ARM (32-bit)
        • AVR (8-bit)
        • dsPIC/PIC24 (16-bit)
        • PIC (8-bit)
        • PIC32 (32-bit)
      • 3.5"
        • ARM (32-bit)
        • FT90x (32-bit)
        • PIC (8-bit)
        • PIC32 (32-bit)
      • 4.3"
        • ARM (32-bit)
        • FT90x (32-bit)
        • PIC (8-bit)
        • PIC32 (32-bit)
      • 5"
        • ARM (32-bit)
        • FT90x (32-bit)
        • PIC32 (32-bit)
      • 7"
        • ARM (32-bit)
        • FT90x (32-bit)
    • MCU Cards
      • PIC (8-bit)
        • 8th Generation
        • 7th Generation
        • 6th Generation
      • dsPIC/PIC24 (16-bit)
        • 8th Generation
        • 7th Generation
        • 6th Generation
      • PIC32 (32-bit)
        • 8th Generation
        • 7th Generation
      • ARM (32-bit)
        • 8th Generation
        • 7th Generation
      • AVR (8-bit)
        • 8th Generation
      • RISC-V (32bit)
        • 8th Generation
    • Accessories
      • TFT Displays
      • LCD Displays
      • LED Displays
      • E-Paper Displays
      • Sensors
      • Headers and Connectors
      • Wire Jumpers and Cables
      • Antennas
      • Batteries
      • RFID/NFC
      • Proto
      • Motors
      • Storage
      • Power
      • Adapters
      • Interface
      • Input/Output
      • Miscellaneous
      • FANware
      • MCUs
      • Books
    • Kits
      • PIC Kits
      • dsPIC/PIC24 Kits
      • PIC32 Kits
      • ARM Kits
      • AVR Kits
      • FT90x Kits
      • 8051 Kits
  • Shop
  • EmbeddedWiki
  • Support
    • Helpdesk
    • Contact us
    • Forum
    • LibStock
    • Learn
    • Let's make
    • Books
  • Services
    • Planet Debug
    • Design Service
    • Product Customization
    • Contract Manufacturing
    • Premium Technical Support
  • News
  • My profile
  • Privacy settings
  • Activity
  • Sign out

Your shoppingcart is empty.
Continue shopping.

MikroElektronika white logo
  • Products
    • click boards icon Click Boards
      • Wireless Connectivity
        • GPS/GNSS
        • GSM/LTE
        • LTE IoT
        • BT/BLE
        • WiFi
        • RFID/NFC
        • GSM+GPS
        • 6LoWPAN
        • ZigBee
        • UWB
        • SigFox
        • Sub-1 GHz Transceievers
        • 2.4 GHz Trancevers
        • LoRa
        • WiFi+BLE
      • Sensors
        • Biometrics
        • Gas
        • Magnetic
        • Motion
        • Optical
        • Pressure
        • Proximity
        • Temperature & humidity
        • Current sensor
        • Miscellaneous
        • Environmental
        • Force
        • Inductance
        • RF meter
        • Click Shields
        • Click Bundles
      • Interface
        • Adapter
        • CAN
        • Port expander
        • RS485
        • USB
        • 1-Wire
        • RS232
        • Ethernet
        • LIN
        • PWM
        • Current
        • DALI
        • I2C
        • Fiber optics
        • SPI
        • DMX
        • CXPI
        • Click Shields
        • Click Bundles
      • Display & LED
        • LED Drivers
        • LED Matrix
        • LED Segment
        • OLED
        • LCD
        • TFT
        • Click Shields
        • Click Bundles
      • Miscellaneous
        • Relay
        • Optocoupler
        • ID
        • Proto
        • Encryption
        • Click Shields
        • Click Bundles
      • Mixed Signal
        • ADC
        • Measurements
        • DAC
        • Digital potentiometer
        • ADC-DAC
        • Click Shields
        • Click Bundles
      • Storage
        • EEPROM
        • FLASH
        • FRAM
        • microSD
        • MRAM
        • SRAM
        • EERAM
        • ReRAM
        • DRAM
        • Click Shields
        • Click Bundles
      • Motor Control
        • Brushed
        • Brushless
        • Servo
        • Stepper
        • Click Shields
        • Click Bundles
      • Audio & Voice
        • Amplifier
        • Microphone
        • Speakers
        • Signal Processing
        • Speech recognition
        • FM
        • MP3
        • Click Shields
        • Click Bundles
      • HMI
        • Capacitive
        • Pushbutton/Switches
        • Potentiometers
        • Rotary encoder
        • Haptic
        • Fingerprint
        • Click Shields
        • Click Bundles
      • Clock & Timing
        • RTC
        • Clock generator
        • Click Shields
        • Click Bundles
      • Power Management
        • Battery charger
        • Boost
        • Buck
        • Linear
        • Buck-Boost
        • Wireless Charging
        • Power Switch
        • USB-C PD
        • Click Shields
        • Click Bundles
      • Click Bundles
      • Click Shields
    • necto icon NECTO
      • NECTO Studio
    • compilers icon Compilers
      • PIC
        • C
          • NECTO Studio
          • mikroC PRO for PIC
        • Basic
          • mikroBasic PRO for PIC
        • Pascal
          • mikroPascal PRO for PIC
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual TFT AI
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • dsPIC/PIC24
        • C
          • NECTO Studio
          • mikroC PRO for dsPIC
        • Basic
          • mikroBasic PRO for dsPIC
        • Pascal
          • mikroPascal PRO for dsPIC
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • PIC32
        • C
          • NECTO Studio
          • mikroC PRO for PIC32
        • Basic
          • mikroBasic PRO for PIC32
        • Pascal
          • mikroPascal PRO for PIC32
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • ARM
        • C
          • NECTO Studio
          • mikroC PRO for ARM
        • Basic
          • mikroBasic PRO for ARM
        • Pascal
          • mikroPascal PRO for ARM
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual TFT AI
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • AVR
        • C
          • NECTO Studio
          • mikroC PRO for AVR
        • Basic
          • mikroBasic PRO for AVR
        • Pascal
          • mikroPascal PRO for AVR
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • FT90x
        • C
          • mikroC PRO for FT90x
        • Basic
          • mikroBasic PRO for FT90x
        • Pascal
          • mikroPascal PRO for FT90x
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
      • 8051
        • C
          • mikroC PRO for 8051
        • Basic
          • mikroBasic PRO for 8051
        • Pascal
          • mikroPascal PRO for 8051
        • Additional Software
          • CODEGRIP WiFi license
          • CODEGRIP SSL license
          • Visual TFT
          • Visual GLCD
          • Package Manager
          • mikroBootloader
          • CAN calculator
          • GLCD Font Creator
          • Timer Calculator
          • MikroPlot
    • dev boards icon Dev Boards
      • PIC (8-bit)
        • 8th Generation
          • Fusion for PIC v8
          • EasyPIC PRO v8
          • EasyPIC PRO v8 over USB-C
          • EasyPIC v8
          • EasyPIC v8 over USB-C
          • UNI-DS v8
          • UNI-DS v8 over USB-C
        • 7th Generation
          • EasyPIC PRO v7a
          • PICPLC16 v7a
          • EasyPIC v7a
          • EasyPIC PRO v7
          • EasyPIC v7
        • 6th Generation
          • PICPLC16 v6
      • dsPIC/PIC24 (16-bit)
        • 8th Generation
          • EasyPIC v8 PIC24/dsPIC33
          • EasyPIC v8 for dsPIC30
          • EasyPIC v8 for dsPIC30 over USB-C
          • Fusion for PIC v8
          • UNI-DS v8
          • UNI-DS v8 over USB-C
        • 7th Generation
          • EasyPIC Fusion v7
          • EasyPIC v7 for dsPIC30
        • 6th Generation
          • Easy24-33 v6
      • PIC32 (32-bit)
        • 8th Generation
          • Fusion for PIC32
          • Fusion for PIC32 over USB-C
          • Fusion for PIC v8
          • UNI-DS v8
          • UNI-DS v8 over USB-C
        • 7th Generation
          • EasyPIC Fusion v7
      • ARM (32-bit)
        • 8th Generation
          • Fusion for ARM v8
          • Fusion for ARM v8 over USB-C
          • Fusion for STM32 v8
          • Fusion for STM32 over USB-C
          • Fusion for KINETIS v8
          • Fusion for Kinetis v8 over USB-C
          • Fusion for TIVA v8
          • Fusion for TIVA v8 over USB-C
          • UNI-DS v8
          • UNI-DS v8 over USB-C
        • 7th Generation
          • EasyMx PRO v7a STM32
          • EasyMx PRO v7 STM32
          • EasyMx PRO v7 Tiva
      • AVR (8-bit)
        • 8th Generation
          • EasyAVR v8
          • EasyAVR PRO v8
          • EasyAVR PRO v8 over USB-C
          • UNI-DS v8
          • UNI-DS v8 over USB-C
        • 7th Generation
          • EasyAVR v7
        • 6th Generation
          • AVRPLC16 v6
      • 8051 (8-bit)
        • 7th generation
          • BIG8051
        • 6th Generation
          • Easy8051 v6
      • PSoC (8-bit)
        • 6th Generation
          • UNI-DS6 Development System
      • RISC-V (32bit)
        • 8th Generation
          • UNI-DS v8
          • UNI-DS v8 over USB-C
      • Universal Boards
        • 8th Generation
          • UNI-DS v8
          • UNI-DS v8 over USB-C
          • Fusion for PIC v8
          • Fusion for ARM v8
        • 7th Generation
          • EasyPIC Fusion v7
        • 6th Generation
          • UNI-DS6
          • mikroBoard for PIC 80-pin
          • mikroBoard for AVR
          • mikroBoard for dsPIC
          • mikroBoard for PSoC
          • mikroBoard for 8051
          • mikroBoard for PIC 40-pin
          • mikroBoard for ARM
          • mikroBoard for ARM 144-pin
      • IoT - Wearable
        • Hexiwear
          • Hexiwear
          • Hexiwear Power User Pack
          • Hexiwear Docking Station
          • Hexiwear Battery Pack
          • Hexiwear Color Pack
          • Hexiwear Workstation
      • Analog Boards
        • 7th Generation
          • Analog System Lab Kit PRO
    • starter boards icon Starter Boards
      • PIC (8-bit)
        • Clicker
          • PIC clicker
        • Clicker 2
          • Clicker 2 for PIC18FJ
          • Clicker 2 for PIC18FK
        • Clicker 4
          • Clicker 4 for PIC18F
          • UNI Clicker
        • Ready
          • Ready for PIC Board
          • Ready for PIC (DIP28)
          • PIC-Ready2 Board
          • MMC Ready Board
        • StartUSB
          • StartUSB for PIC
      • dsPIC/PIC24 (16-bit)
        • Clicker 2
          • Clicker 2 for PIC24
          • Clicker 2 for dsPIC33
        • Clicker 4
          • UNI Clicker
        • Ready
          • dsPIC-Ready1 Board
          • dsPIC-Ready2 Board
          • DsPIC-Ready3 Board
          • dsPIC-Ready4 Board
      • PIC32 (32-bit)
        • Clicker
          • PIC32MX clicker
          • 6LoWPAN Clicker
          • PIC32MZ clicker
        • Clicker 2
          • Clicker 2 for PIC32MX
          • Clicker 2 for PIC32MZ
        • Clicker 4
          • UNI Clicker
        • MINI
          • MINI-32 Board
          • MINI-32 for PIC32MZ
        • Flip&Click
          • Flip&Click PIC32MZ
      • ARM (32-bit)
        • Clicker
          • RA4M1 Clicker
          • Kinetis Clicker
          • MSP432 Clicker
          • CEC1702 clicker
          • CEC1302 Clicker
          • STM32 M4 clicker
        • Clicker 2
          • Clicker 2 for STM32
          • Clicker 2 for Kinetis
          • Clicker 2 for CEC1702
          • Clicker 2 for MSP432
          • Clicker 2 for CEC1302
          • Clicker 2 for PSoC 6
        • Clicker 4
          • Clicker 4 for STM32F745VG
          • Clicker 4 for STM32F4
          • Clicker 4 for TMPM3H
          • Clicker 4 for TMPM4K
          • Clicker 4 for STM32
          • UNI Clicker
        • MINI
          • MINI-M4 for STM32
          • MINI-M4 For Kinetis
          • MINI-M4 for Tiva
          • MINI-M4 for Stellaris
          • MINI-M4 for MSP432
          • MINI-M0 for STM32
        • Flip&Click
          • Flip&Click SAM3X
      • AVR (8-bit)
        • Clicker 4
          • UNI Clicker
        • MINI
          • MINI-AT Board - 3.3V
          • MINI-AT Board - 5V
        • Ready
          • Ready for AVR Board
          • Ready For XMEGA
          • mikroXMEGA Board
          • AVR-Ready2 Board
        • StartUSB
          • StartUSB for AVR
      • 8051 (8-bit)
        • Ready
          • 8051-Ready Board
      • FT90x (32-bit)
        • Clicker 2
          • Clicker 2 for FT90x
      • Miscellaneous
        • USB
          • USB Wizard
          • Quail
          • FlowPaw Kit
      • Universal Boards
        • Clicker 4
          • UNI Clicker
    • prog-debug icon Prog-Debug
      • PIC (8-bit)
        • CODEGRIP
          • UNI CODEGRIP
          • UNI CODEGRIP - USB-C
          • CODEGRIP for PIC
          • CODEGRIP for PIC USB-C
        • mikroProg
          • mikroProg for PIC
      • dsPIC/PIC24 (16-bit)
        • CODEGRIP
          • UNI CODEGRIP
          • UNI CODEGRIP - USB-C
          • CODEGRIP for PIC
        • mikroProg
          • mikroProg for dsPIC
      • PIC32 (32-bit)
        • CODEGRIP
          • UNI CODEGRIP
          • UNI CODEGRIP - USB-C
          • CODEGRIP for PIC
          • CODEGRIP for PIC USB-C
        • mikroProg
          • mikroProg for PIC32
      • ARM (32-bit)
        • CODEGRIP
          • UNI CODEGRIP
          • UNI CODEGRIP USB-C
          • CODEGRIP for ARM
          • CODEGRIP for ARM USB-C
          • CODEGRIP for STM32
          • CODEGRIP for KINETIS
          • CODEGRIP for Tiva
          • CODEGRIP for Tiva USB-C
        • mikroProg
          • mikroProg for STM32
          • mikroProg for Tiva
          • mikroProg for Kinetis
          • mikroProg for CEC
          • mikroProg for MSP432
          • mikroProg for PSoC 5LP
      • AVR (8-bit)
        • CODEGRIP
          • CODEGRIP for AVR
          • CODEGRIP for AVR - USB-C
          • UNI CODEGRIP
          • UNI CODEGRIP - USB-C
        • mikroProg
          • mikroProg for AVR
      • 8051 (8-bit)
        • mikroProg
          • mikroProg for 8051
      • FT90x (32-bit)
        • mikroProg
          • mikroProg for FT90x
    • smart displays icon Smart Displays
      • 2.8"
        • ARM (32-bit)
        • AVR (8-bit)
        • dsPIC/PIC24 (16-bit)
        • PIC (8-bit)
        • PIC32 (32-bit)
      • 3.5"
        • ARM (32-bit)
        • FT90x (32-bit)
        • PIC (8-bit)
        • PIC32 (32-bit)
      • 4.3"
        • ARM (32-bit)
        • FT90x (32-bit)
        • PIC (8-bit)
        • PIC32 (32-bit)
      • 5"
        • ARM (32-bit)
        • FT90x (32-bit)
        • PIC32 (32-bit)
      • 7"
        • ARM (32-bit)
        • FT90x (32-bit)
    • mcu cards icon MCU Cards
      • PIC (8-bit)
        • 8th Generation
        • 7th Generation
        • 6th Generation
      • dsPIC/PIC24 (16-bit)
        • 8th Generation
        • 7th Generation
        • 6th Generation
      • PIC32 (32-bit)
        • 8th Generation
        • 7th Generation
      • ARM (32-bit)
        • 8th Generation
        • 7th Generation
      • AVR (8-bit)
        • 8th Generation
      • RISC-V (32bit)
        • 8th Generation
    • accessories icon Accessories
      • TFT Displays
      • LCD Displays
      • LED Displays
      • E-Paper Displays
      • Sensors
      • Headers and Connectors
      • Wire Jumpers and Cables
      • Antennas
      • Batteries
      • RFID/NFC
      • Proto
      • Motors
      • Storage
      • Power
      • Adapters
      • Interface
      • Input/Output
      • Miscellaneous
      • FANware
      • MCUs
      • Books
    • kits icon Kits
      • PIC Kits
      • dsPIC/PIC24 Kits
      • PIC32 Kits
      • ARM Kits
      • AVR Kits
      • FT90x Kits
      • 8051 Kits
  • Shop
  • EmbeddedWiki
  • Support
    • Helpdesk
    • Contact us
    • Forum
    • LibStock
    • Learn
    • Let's make
    • Books
  • Services
    • Planet Debug
    • Design Service
    • Product Customization
    • Contract Manufacturing
    • Premium Technical Support
  • News
  • Price :

    More info
Reset filter
  • 0
Authentication
Account

Create account

Forgot your password?

Your cart is empty !
View cart ( )
  1. Home
  2. ebooks
  3. Architecture and programming of 8051 MCUs
  4. examples
MikroElektronika books

6.3 Examples

 

The schematic below is used in the several following examples:

8051-chapter-06-image-023 Apart from components necessary for the operation of the microcontroller such as oscillator with capacitors and the simplest reset circuit, there are also several LEDs and one push button. These are used to indicate the operation of the program. All LEDs are polarized in such a way that they are activated by driving a microcontroller pin low (logic 0).

LED Blinking

The purpose of this example is not to demonstrate the operation of LEDs, but the operating speed of the microcontroller. Simply put, in order to enable LED blinking to be visible, it is necessary to provide sufficient amount of time to pass between on/off states of LEDs. In this example time delay is provided by executing a subroutine called Delay. It is a triple loop in which the program remains for approximately 0.5 seconds and decrements values stored in registers R0, R1 or R2. After returning from the subroutine, the pin state is inverted and the same procedure is repeated...
;************************************************************************
;* PROGRAM NAME : Delay.ASM
;* DESCRIPTION: Program turns on/off LED on the pin P1.0
;* Software delay is used (Delay).
;************************************************************************
;BASIC DIRECTIVES
$MOD53
$TITLE(DELAY.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;STACK
        DSEG    AT    03FH
STACK_START:    DS    040H

;RESET VECTORS
       CSEG     AT    0
       JMP      XRESET                  ;Reset vector
       
       ORG      100H
       
XRESET: MOV     SP,#STACK_START         ;Define Stack pointer
        MOV     P1,#0FFh                ;All pins are configured as inputs

LOOP:
        CPL     P1.0                    ;Pin P1.0 state is inverted
        LCALL   Delay                   ;Time delay
        SJMP    LOOP

Delay:
        MOV     R2,#20                  ;500 ms time delay
F02:    MOV     R1,#50                  ;25 ms
F01:    MOV     R0,#230
        DJNZ    R0,$
        DJNZ    R1,F01
        DJNZ    R2,F02

END                                     ;End of program

Using Watch-dog Timer

This example describes how the watch-dog timer should not operate. The watch-dog timer is properly adjusted (nominal time for counting is 1024mS), but instruction used to reset it is intentionally left out so that this timer always "wins". As a result, the microcontroller is reset (state in registers remains unchanged), program starts execution from the beginning and the number in register R3 is incremented by 1 and then copied to port P1. LEDs display this number in binary format...
;************************************************************************
;* PROGRAM NAME : WatchDog.ASM
;* DESCRIPTION : After watch-dog reset, program increments number in
;* register R3 and shows it on port P1 in binary format.
;************************************************************************

;BASIC DIRECTIVES
$MOD53
$TITLE(WATCHDOG.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

WMCON     DATA    96H
WDTEN     EQU     00000001B        ; Watch-dog timer is enabled
PERIOD    EQU     11000000B        ; Nominal Watch-dog period is set to be 1024ms 

;RESET    VECTOR
          CSEG    AT      0
          JMP     XRESET           ; Reset vector

          CSEG
          ORG     100H

XRESET:   ORL     WMCON,#PERIOD    ; Define Watch-dog period
          ORL     WMCON,#WDTEN     ; Watch-dog timer is enabled

          MOV     A,R3             ; R3 is moved to port 1
          MOV     P1,A
          INC     R3               ; Register R3 is incremented by 1

LAB:      SJMP    LAB              ; Wait for watch-dog reset

          END                      ; End of program

Timer T0 in mode 1

This program spends most of its time in an endless loop waiting for timer T0 to count up a full cycle. When it happens, an interrupt is generated, routine TIM0_ISR is executed and logic zero (0) on port P1 is shifted right by one bit. This is another way of demonstrating the operating speed of the microcontroller since each shift means that counter T0 has counted up 216 pulses!
;************************************************************************
;* PROGRAM NAME : Tim0Mod1.ASM
;* DESCRIPTION: Program rotates "0" on port 1. Timer T0 in mode 1 is
;* used
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(TIM0MOD1.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;DECLARATION OF VARIABLES

;STACK

        DSEG     AT     03FH
STACK_START:     DS     040H

;RESET VECTORS
       CSEG      AT 0
       JMP       XRESET             ; Reset vector

       ORG       00BH
       JMP       TIM0_ISR           ; Timer T0 reset vector

       ORG       100H

XRESET: MOV      SP,#STACK_START    ; Define Stack pointer
       MOV       TMOD,#01H          ; MOD1 is selected
       MOV       A,#0FFH
       MOV       P1,#0FFH
       SETB      TR0                ; Timer T0 is enabled
       MOV       IE,#082H           ; Interrupt enabled
       CLR       C

LOOP1: SJMP      LOOP1              ; Remain here

TIM0_ISR:        RRC     A          ; Rotate accumulator A through Carry flag
                 MOV     P1,A       ; Contents of accumulator A is moved to PORT1
                 RETI               ; Return from interrupt

       END                          ; End of program

Timer T0 in Split mode

Similarly to the previous example, the program spends most of its time in a loop called LOOP1. Since 16-bit Timer T0 is split into two 8-bit timers, there are also two interrupt sources. The first interrupt is generated after timer T0 reset. Routine TIM0_ISR in which logic zero (0) bit on port P1 rotates is executed. Outside looking, it seems that LEDs move. Another interrupt is generated upon Timer T1 reset. Routine TIM1_ISR in which the bit state DIRECTION inverts is executed. Since this bit determines direction of bit rotation then the moving direction of LED is also changed. If you press a push button T1 at some point, a logic zero (0) on the P3.2 output will disable Timer T1.
;************************************************************************
;* PROGRAM NAME : Split.ASM
;* DESCRIPTION: Timer TL0 rotates bit on port P1, while TL1 determines
;* the rotation direction. Both timers operate in mode
;* 3. Logic zero (0) on output P3.2 disables rotation on port P1.
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(SPLIT.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;DECLARATION OF VARIABLES

        BSEG    AT    0

;DECLARATION OF BIT-VARIABLES

SEMAPHORE:      DBIT    8
DIRECTION       BIT     SEMAPHORE

;STACK
        DSEG    AT    03FH
STACK_START:    DS    040H

;RESET VECTORS

        CSEG    AT    0
        JMP     XRESET                    ; Reset vector
        ORG     00BH

        JMP     TIM0_ISR                  ; Timer T0 reset vector

        ORG     01BH
        JMP     TIM1_ISR                  ; Timer T1 reset vector

        ORG     100H
XRESET: MOV     SP,#STACK_START           ; Define Stack pointer
        MOV     TMOD,#00001011B           ; Define MOD3
        MOV     A,#0FFH
        MOV     P1,#0FFH
        MOV     R0,#30D
        SETB    TR0                       ; TL0 is turned on
        SETB    TR1                       ; TL1 is turned on
        MOV     IE,#08AH                  ; Interrupt enabled
        CLR     C
        CLR     DIRECTION                 ; Rotate to the right

LOOP1:  SJMP    LOOP1                     ; Remain here

TIM0_ISR:
        DJNZ    R0,LAB3                   ; Slow down rotation by 256 times
        JB      DIRECTION,LAB1
        RRC     A                         ; Rotate contents of Accumulator to the right through
                                          ; Carry flag

        SJMP    LAB2
LAB1:   RLC     A                         ; Rotate contents of Accumulator to the left through
                                          ; Carry flag
LAB2:   MOV     P1,A                      ; Contents of Accumulator is moved to port P1
LAB3:   RETI                              ; Return from interrupt

TIM1_ISR:
        DJNZ    R1,LAB4                   ; Slow down direction of rotation by 256 times
        DJNZ    R2,LAB4                   ; When time expires, change rotation direction
        CPL     SMER
        MOV     R2,#30D
LAB4:   RETI

        END                               ; End of program

Simultaneous use of timers T0 and T1

This program can be considered as continuation of the previous one. They share the same idea, but in this case true timers T0 and T1 are used. In order to demonstrate the operation of both timers on the same port at the same time, timer T0 reset is used to shift logic zero (0) on the port, while Timer T1 reset is used to change rotation direction. This program spends most of its time in the loop LOOP1 waiting for an interrupt to be caused by reset. By checking the DIRECTION bit, information on rotation direction of both bits in accumulator as well as of moving port LED is obtained.
;************************************************************************
;* PROGRAM NAME : Tim0Tim1.ASM
;* DESCRIPTION: Timer TO rotates bit on port P1 while Timer1
;* changes rotation direction. Both timers are configured to operate in mode 1.
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(TIM0TIM1.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;DECLARATION OF VARIABLES

       BSEG    AT    0

;DECLARATION OF BIT-VARIABLES

SEMAPHORE:      DBIT    8
DIRECTION       BIT     SEMAPHORE

;STACK
       DSEG    AT    03FH
STACK_START:   DS    040H

;RESET VECTORS
       CSEG    AT    0
       JMP     XRESET                     ; Reset vector

       ORG     00BH                       ; Timer 0 Reset vector
       JMP     TIM0_ISR

       ORG     01BH                       ; Timer 1 Reset vector
       JMP     TIM1_ISR

       ORG     100H


XRESET: MOV    SP,#STACK_START            ; Define Stack pointer
        MOV    TMOD,#11H                  ; Select MOD1 for both timers
        MOV    A,#0FFH
        MOV    P1,#0FFH
        MOV    R0,#30D                    ; R0 is initialized
        SETB   TR0                        ; TIMER0 is turned on
        SETB   TR1                        ; TIMER1 is turned on
        MOV    IE,#08AH                   ; Timer0 and Timer1 Interrupt enabled
        CLR    C
        CLR    DIRECTION                  ; Rotate to the right

LOOP1:  SJMP   LOOP1                      ; Remain here


TIM0_ISR:
        JB     DIRECTION,LAB1
        RRC A                             ; Rotate contents of accumulator to the right through
                                          ; Carry flag
        SJMP   LAB2
LAB1:   RLC    A                          ; Rotate contents of Accumulator to the left through
                                          ; Carry flag
LAB2:   MOV    P1,A                       ; Contents of Accumulator is moved to port P1
        RETI                              ; Return from interrupt

TIM1_ISR:
        DJNZ   R0,LAB3                    ; When time expires, change rotation direction
        CPL    DIRECTION
        MOV    R0,#30D                    ; Initialize R0
LAB3:
        RETI
        END                               ; End of program

Using Timer T2

This example describes the use of Timer T2 configured to operate in Auto-Reload mode. In this very case, LEDs are connected to port P3 while the push button used for forced timer reset (T2EX) is connected to the P1.1 pin. Program execution is similar to the previous examples. When timer ends counting, an interrupt is enabled and subroutine TIM2_ISR is executed, thus rotating a logic zero (0) in accumulator and moving the contents of accumulator to the P3 pin. At last, flags which caused an interrupt are cleared and program returns to the loop LOOP1 where it remains until a new interrupt request arrives... If push button T2EX is pressed, timer is temporarily reset. This push button resets timer, while push button RESET resets the microcontroller. 8051-chapter-06-image-024
;************************************************************************
;* PROGRAM NAME : Timer2.ASM
;* DESCRIPTION: Program rotates log. "0" on port P3. Timer2 determines
;* the speed of rotation and operates in auto-reload mode
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(TIMER2.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;DEFINITION OF VARIABLES

        T2MOD    DATA     0C9H
;STACK
        DSEG     AT       03FH
STACK_START:     DS       040H

;RESET VECTORS
        CSEG     AT       0
        JMP      XRESET                   ; Reset vector

        ORG      02BH                     ; Timer T2 Reset vector
        JMP      TIM2_ISR

        ORG      100H

XRESET: MOV      SP,#STACK_START          ; Define Stack pointer
        MOV      A,#0FFH
        MOV      P3,#0FFH
        MOV      RCAP2L,#0FH              ; Prepare 16-bit auto-reload mode
        MOV      RCAP2L,#01H
        CLR      CAP2                     ; Enable 16-bit auto-reload mod 
        SETB     EXEN2                    ; Pin P1.1 reset is enabled
        SETB     TR2                      ; Enable Timer T2 
        MOV      IE,#0A0H                 ; Interrupt is enabled
        CLR      C

LOOP1:  SJMP     LOOP1                    ; Remain here

TIM2_ISR:        RRC      A               ; Rotate contents of Accumulator to the right through
                                          ; Carry flag
                 MOV      P3,A            ; Move the contents of Accumulator A to PORT3
                 CLR      TF2             ; Clear timer T2 flag TF2 
                 CLR      EXF2            ; Clear timer T2 flag EXF2 
                 RETI                     ; Return from interrupt

                 END                      ; End of program

Using External Interrupt

Here is another example of interrupt execution. An external iterrupt is generated when a logic zero (0) is present on pin P3.2 or P3.3. Depending on which input is active, one of two routines will be executed: A logic zero (0) on the P3.2 pin initiates execution of interrupt routine Isr_Int0, thus incrementing number in register R0 and copying it to port P0. Logic zero on the P3.3 pin initiates execution of subroutine Isr_Int1, number in register R1 is incremented by 1 and then copied to port P1. In short, each press on push buttons INT0 and INT1 will be counted and immediately shown in binary format on appropriate port (LED which emitts light represents a logic zero (0)). 8051-chapter-06-image-025
;************************************************************************
;* PROGRAM NAME : Int.ASM
;* DESCRIPTION : Program counts interrupts INT0 generated by appearance of high-to-low
;* transition signal on pin P3.2 Result appears on port P0. Interrupts INT1 are also 
;* counted up at the same time. They are generated byappearing high-to-low transition
;* signal on pin P3. The result appears on port P1.
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(INT.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;RESET VECTORS

        CSEG     AT     0
        JMP      XRESET               ; Reset vector

        ORG      003H                 ; Interrupt routine address for INT0
        JMP      Isr_Int0
        ORG 013H                      ; Interrupt routine address for INT1
        JMP      Isr_Int1

        ORG      100H
XRESET:
        MOV      TCON,#00000101B      ; Interrupt INT0 is generated by appearing
                                      ; high-to-low transition signal on pin P3.2
                                      ; Interrupt INT0 is generated by appearing
                                      ; high-to-low transition signal on pin P3.3
        MOV      IE,#10000101B        ; Interrupt enabled
        MOV      R0,#00H              ; Counter starting value
        MOV      R1,#00H
        MOV      P0,#00H              ; Reset port P0
        MOV      P1,#00H              ; Reset port P1

LOOP:   SJMP     LOOP                 ; Remain here

Isr_Int0:
        INC R0                        ; Increment value of interrupt INT0 counter
        MOV P0,R0
        RETI

Isr_Int1:
        INC R1                        ; Increment value of interrupt INT1 counter
        MOV P1,R1
        RETI
        END                           ; End of program

Using LED display

The following examples describe the use of LED displays. Common chatode displays are used here, which means that all built-in LEDs are polarized in such a way that their anodes are connected to the microcontroller pins. Since the common way of thinking is that logic one (1) turns something on and logic zero (0) turns something of, Low Current displays (low power consumption) and their diodes (segments) are connected serially to resistors of relatively high resistance. In order to save I/O pins, four LED displays are connected to operate in multiplex mode. It means that all segments having the same name are connected to one output port each and only one display is active at a time. Tranzistors and segmenats on displays are quickly activated, thus making impression that all digits are active simultaneously. 8051-chapter-06-image-026

Writing digits on LED display

This program is a kind of “warming up” exerciese before real work starts. The purpose of this example is to display something on any display. Multiplex mode is not used this time. Instead, digit 3 is displayed on only one of them (first one on the right). Since the microcontroller “does not know” how we write number 3, a small subroutine called Disp is used (the microcontroller writes this number as 0000 0011). This subroutine enables all decimal digits (0-9) to be displayed (masked). The principle of operation is simple. A number to be displayed is added to the current address and program jump is executed. Different numbers require different jump length. Precisely determined combination of zeroes and ones appears on each of these new locations (digit 1 mask, digit 2 mask...digit 9 mask). When this combination is transferred to the port, the display shows desired digit.
;************************************************************************
;* PROGRAM NAME : 7Seg1.ASM
;* DESCRIPTION: Program displays number "3" on 7-segment LED display
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(7SEG1.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;STACK
          DSEG     AT     03FH
STACK_START:       DS     040H

;RESET VECTORS
          CSEG     AT     0
          JMP      XRESET               ; Reset vector

          ORG      100H

XRESET:   MOV      SP,#STACK_START      ; Define Stack pointer
          MOV      P1,#0                ; Turn off all segments on displays
          MOV      P3,#20h              ; Activate display D4

LOOP:
          MOV      A,#03                ; Send number “3” to display
          LCALL    Disp                 ; Perform appropriate masking for the number
          MOV      P1,A
          SJMP     LOOP

Disp:                                   ; Subroutine for displaying digits
          INC      A
          MOVC     A,@A+PC
          RET
          DB       3FH                  ; Digit 0 mask
          DB       06H                  ; Digit 1 mask
          DB       5BH                  ; Digit 2 mask
          DB       4FH                  ; Digit 3 mask
          DB       66H                  ; Digit 4 mask
          DB       6DH                  ; Digit 5 mask
          DB       7DH                  ; Digit 6 mask
          DB       07H                  ; Digit 7 mask
          DB       7FH                  ; Digit 8 mask
          DB       6FH                  ; Digit 9 mask
          END                           ; End of program

Writing and changing digits on LED display

This program is only an extended verson of the previous one. There is only one digit active- the first one on the right, and there is no use of multiplexing. Unlike the previous example, all decimal numbers are displayed (0-9). In order to enable digits to change at reasonable pace, a soubroutine L2 which causes a short time delay is executed prior to each change occurs. Basically, the whole process is very simple and takes place in the main loop called LOOP which looks as follows:
  1. R3 is copied to Accumulator and subroutine for masking digits Disp is executed;
  2. Accumulator is copied to the port and displayed;
  3. The contents of the R3 register is incremented;
  4. It is checked whether 10 cycles are counted or not. If it is, register R3 is reset in order to enable counting to start from 0; and
  5. Instruction labeled as L2 within subroutine is executed.
;************************************************************************
;* PROGRAM NAME: 7Seg2.ASM
;* DESCRIPTION: Program writes numbers 0-9 on 7-segment LED display
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(7SEG2.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;STACK
         DSEG     AT     03FH
STACK_START:      DS     040H

;RESET VECTORS
         CSEG     AT     0
         JMP      XRESET                   ; Reset vector

         ORG      100H

XRESET:  MOV      SP,#STACK_START          ; Define Stack pointer
         MOV      R3,#0                    ; Counter initial value
         MOV      P1,#0                    ; Turn off all display segments
         MOV      P3,#20h                  ; Activate display D4

LOOP:
         MOV      A,R3
         LCALL    Disp                     ; Perform appropriate masking for number in
                                           ; Accumulator
         MOV      P1,A
         INC      R3                       ; Increment number in register by 1
         CJNE     R3,#10,L2                ; Check whether the number 10 is in R3
         MOV      R3,#0                    ; If it is, reset counter
L2:
         MOV      R2,#20                   ; 500 mS time delay
F02:     MOV      R1,#50                   ; 25 mS
F01:     MOV      R0,#230
         DJNZ     R0,$
         DJNZ     R1,F01
         DJNZ     R2,F02
         SJMP     LOOP

Disp:                                      ; Subroutine for writing digits
         INC      A
         MOVC     A,@A+PC
         RET
         DB       3FH                      ; Digit 0 mask
         DB       06H                      ; Digit 1 mask
         DB       5BH                      ; Digit 2 mask
         DB       4FH                      ; Digit 3 mask
         DB       66H                      ; Digit 4 mask
         DB       6DH                      ; Digit 5 mask
         DB       7DH                      ; Digit 6 mask
         DB       07H                      ; Digit 7 mask
         DB       7FH                      ; Digit 8 mask
         DB       6FH                      ; Digit 9 mask

         END                               ; End of program

Writing two-digit number on LED display

It is time for time multiplexing! This is the simplest example which displays the number 23 on two displays in such a way that one of them displays units, while the other displays tens. The most important thing in the program is time synchronization. Otherwise, everything is very simple. Transistor T4 enables display D4 and at the same time a bit combination corresponding to the digit 3 is set on the port. After that, transistor T4 is disabled and the whole process is repeated using transistor T3 and display D3 in order to display digit 2. This procedure must be continuosly repeated in order to make impression that both displays are active at the same time.
;************************************************************************
;* PROGRAM NAME: 7Seg3.ASM
;* DESCRIPTION: Program displays number "23" on 7-segment LED display
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(7SEG3.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;STACK
         DSEG      AT      03FH
STACK_START:       DS      040H

;RESET VECTORS
         CSEG      AT      0
         JMP       XRESET                    ; Reset vector

         ORG       100H
XRESET:  MOV       SP,#STACK_START           ; Define Stack pointer

LOOP:    MOV       P1,#0                     ; Turn off all display segments
         MOV       P3,#20h                   ; Activate display D4
         MOV       A,#03                     ; Write digit 3 on display D4
         LCALL     Disp                      ; Find appropriate mask for that digit
         MOV       P1,A                      ; Put the mask on the port
         MOV       P1,#0                     ; Turn off all dislay segments
         MOV       P3,#10h                   ; Activate display D3
         MOV       A,#02                     ; Write digit 2 on display D3
         LCALL     Disp                      ; Find mask for that digit
         MOV       P1,A                      ; Put the mask on the port
         SJMP      LOOP                      ; Return to the label LOOP

Disp:                                        ; Subroutine for writing digits
         INC       A
         MOVC      A,@A+PC
         RET
         DB        3FH                       ; Digit 0 mask
         DB        06H                       ; Digit 1 mask
         DB        5BH                       ; Digit 2 mask
         DB        4FH                       ; Digit 3 mask
         DB        66H                       ; Digit 4 mask
         DB        6DH                       ; Digit 5 mask
         DB        7DH                       ; Digit 6 mask
         DB        07H                       ; Digit 7 mask
         DB        7FH                       ; Digit 8 mask
         DB        6FH                       ; Digit 9 mask

         END                                 ; End of program

Using four digit LED display

In this example all four displays, instead of two, are active so that it is possible to write numbers from 0 to 9999. Here, the number 1 234 is displayed. After initialization, the program remains in the loop LOOP where digital multiplexing is performed. The subroutine Disp is used to convert binary numbers into corresponding combinations of bits for the purpose of activating display lighting segments.
;************************************************************************
;* PROGRAM NAME : 7Seg5.ASM
;* DESCRIPTION : Program displays number"1234" on 7-segment LED display
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(7SEG5.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;STACK
         DSEG     AT     03FH
STACK_START:      DS     040H

;RESET VECTORS
         CSEG     AT     0
         JMP      XRESET                  ; Reset vector

         ORG      100H

XRESET:  MOV      SP,#STACK_START         ; Define Stack pointer

LOOP:    MOV      P1,#0                   ; Turn off all display segments 
         MOV      P3,#20h                 ; Activate display D4
         MOV      A,#04                   ; Write digit 4 on display D4
         LCALL    Disp                    ; Find mask for that digit
         MOV      P1,A                    ; Put the mask on the port
         MOV      P1,#0                   ; Turn off all display segments
         MOV      P3,#10h                 ; Activate display D3
         MOV      A,#03                   ; Write digit 3 on display D3
         LCALL    Disp                    ; Find mask for that digit
         MOV      P1,A                    ; Put the mask on the port
         MOV      P1,#0                   ; Turn off all display segments
         MOV      P3,#08h                 ; Activate display D2
         MOV      A,#02                   ; Write digit 2 on display D2
         LCALL    Disp                    ; Find mask for that digit
         MOV      P1,A                    ; Put the mask on the port
         MOV      P1,#0                   ; Turn off all display segments
         MOV      P3,#04h                 ; Activate display D1
         MOV      A,#01                   ; Write digit 1 on display D1
         LCALL    Disp                    ; Find mask for that digit
         MOV      P1,A                    ; Put the mask on the port
         SJMP     LOOP                    ; Return to the lable LOOP

Disp:                                     ; Subroutine for writing digits
         INC      A
         MOVC     A,@A+PC
         RET
         DB       3FH                     ; Digit 0 mask
         DB       06H                     ; Digit 1 mask
         DB       5BH                     ; Digit 2 mask
         DB       4FH                     ; Digit 3 mask
         DB       66H                     ; Digit 4 mask
         DB       6DH                     ; Digit 5 mask
         DB       7DH                     ; Digit 6 mask
         DB       07H                     ; Digit 7 mask
         DB       7FH                     ; Digit 8 mask
         DB       6FH                     ; Digit 9 mask

         END ; End of program

LED display as a two digit counter

Things are getting complicated... In addition to two digit multiplexing, the microcontroller also performs other operations. In this example, contents of registers R2 and R3 are incremented in order to display number counting (97, 98, 99, 00, 01, 02...). This time, transistors which activate displays remain turned on for 25mS. The soubroutine Delay is in charge of that. Even though digits shift much slower now, it is still not slow enough to make impression of simultaneous operation. After both digits of a number blink for 20 times, the number on displays is incremented by 1 and the whole procedure is repeated.
;************************************************************************
;* PROGRAM NAME : 7Seg4.ASM
;* DESCRIPTION: Program displays numbers 0-99 on 7-segment LED displays
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(7SEG4.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;STACK
         DSEG      AT      03FH
STACK_START:       DS      040H

;RESET VECTORS
         CSEG      AT      0
         JMP       XRESET                   ; Reset vector

         ORG       100H

XRESET:  MOV       SP,#STACK_START          ; Define Stack pointer
         MOV       R2,#0                    ; Counter starting value
         MOV       R3,#0
         MOV       R4,#0

LOOP:    INC       R4                       ;Wait for display to be "refreshed" for 100 times 
         CJNE      R4,#20d,LAB1             ;before incrementing the counter
         MOV       R4,#0
         MOV       P1,#0                    ; Turn off all display segments 
         INC       R2                       ; Increment Register containing units by 1
         CJNE      R2,#10d,LAB1
         MOV       R2,#0                    ; Reset units
         INC       R3                       ; Increment Register with tens by 1
         CJNE      R3,#10d,LAB1             ;
         MOV       R3,#0                    ; Reset tens

LAB1:
         MOV       P3,#20h                  ; Activate display D4
         MOV       A,R2                     ; Copy Register containing units to A
         LCALL     Disp                     ; Call mask for that digit
         MOV       P1,A                     ; Write units on display D4
         LCALL     Delay                    ; 25ms delay
         MOV       P1,#0                    ; Turn off all display segments
         MOV       P3,#10h                  ; Activate display D3
         MOV       A,R3                     ; Copy Register contaning tens to A
         LCALL     Disp                     ; Call mask for that digit
         MOV       P1,A                     ; Write tens on display D3
         LCALL     Delay                    ; 25ms delay
         SJMP      LOOP

Delay:
         MOV       R1,#50                   ; 5 ms delay
F01:     MOV       R0,#250
         DJNZ      R0,$
         DJNZ      R1,F01
         RET

Disp:                                       ; Subroutine for displaying digits
         INC       A
         MOVC      A,@A+PC
         RET
         DB        3FH                      ; Digit 0 mask
         DB        06H                      ; Digit 1 mask
         DB        5BH                      ; Digit 2 mask
         DB        4FH                      ; Digit 3 mask
         DB        66H                      ; Digit 4 mask
         DB        6DH                      ; Digit 5 mask
         DB        7DH                      ; Digit 6 mask
         DB        07H                      ; Digit 7 mask
         DB        7FH                      ; Digit 8 mask
         DB        6FH                      ; Digit 9 mask

         END                                ; End of program

Handling EEPROM

This program writes data to on-chip EEPROM memory. In this case, the data is a hexadecimal number 23 which is to be written to the location with address 00. To make sure that this number is correctly written, the same location of EEPROM is read 10mS later in order to compare these two numbers. If they match, F will be displayed. Otherwise, E will be displayed on the LED display (Error).
;************************************************************************
;* PROGRAM NAME: EEProm1.ASM
;* DESCRIPTION: Programming EEPROM at address 0000hex and displaying message
;* on LED display.
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(EEPROM1.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

WMCON     DATA     96H
EEMEN     EQU      00001000B              ; Access to internal EEPROM is enabled
EEMWE     EQU      00010000B              ; Write to EEPROM is enabled
TEMP      DATA     030H                   ; Define Auxiliary register

THE END   EQU      071H                   ; Display "F" 
ERROR     EQU      033H                   ; Display "E" 

;STACK
          DSEG     AT     03FH
STACK_START:       DS     040H

;RESET VECTORS
          CSEG     AT     0
          JMP      XRESET                 ; Reset vector

          ORG      100H

XRESET:   MOV      IE,#00                 ; All interrupts are disabled
          MOV      SP,#STACK_START

          MOV      DPTR,#0000H            ; Choose location address in EEPROM
          ORL      WMCON,#EEMEN           ; Access to EEPROM is enabled
          ORL      WMCON,#EEMWE           ; Write to EEPROM is enabled
          MOV      TEMP,#23H              ; Number written to EEPROM is moved to
          MOV      A,TEMP                 ; register TEMP and Accumulator
          MOVX     @DPTR,A                ; Write byte to EEPROM
          CALL     DELAY                  ; 10ms delay
          MOVX     A,@DPTR                ; Read the same location and compare to TEMP,
          CJNE     A,TEMP,ERROR           ; If they don't match, jump to label ERROR
          MOV      A,#KRAJ                ; Display F (correct)
          MOV      P1,A
          XRL      WMCON,#EEMWE           ; Write to EEPROM is disabled
          XRL      WMCON,#EEMEN           ; Access to EEPROM is disabled
LOOP1:    SJMP     LOOP1                  ; Remain here

ERROR:    MOV      A,#ERROR               ; Display E (error)
          MOV      P1,A
LOOP2:    SJMP     LOOP2

DELAY:    MOV      A,#0AH                 ; Delay
          MOV      R3,A
LOOP3:    NOP
LOOP4:    DJNZ     B,LOOP4
LOOP5:    DJNZ     B,LOOP5
          DJNZ     R3,LOOP3
          RET

          END                             ; End of program

Data reception via UART

In order to enable successful UART serial communication, it is necessary to meet specific rules of the RS232 standard. It primarily refers to voltage levels required by this standard. Accordingly, -10V stands for logic one (1) in the message, while +10V stands for logic zero (0). The microcontroller converts accurately data into serial format, but its power supply voltage is only 5V. Since it is not easy to convert 0V into 10V and 5V into -10V, this operation is on both transmit and receive side left to a specialized IC circuit. Here, the MAX232 by MAXIM is used because it is widespread, cheap and reliable. This example shows how to receive message sent by a PC. Timer T1 generates boud rate. Since the 11.0592 MHz quartz crystal is used here, it is easy to obtain standard baud rate which amouts to 9600 bauds. Each received data is immediately transferred to port P1 pins. 8051-chapter-06-image-027
;************************************************************************
;* PROGRAM NAME : UartR.ASM
;* DESCRIPTION: Each data received from PC via UART appears on the port
;* P1.
;*
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(UARTR.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;STACK
         DSEG     AT     03FH
STACK_START:      DS     040H

;RESET VECTORS
         CSEG     AT     0
         JMP      XRESET                ; Reset vector
         ORG      023H                  ; Starting address of UART interrupt routine
         JMP      IR_SER

         ORG      100H

XRESET:  MOV      IE,#00                ; All interrupts are disabled
         MOV      SP,#STACK_START       ; Initialization of Stack pointer
         MOV      TMOD,#20H             ; Timer1 in mode2
         MOV      TH1,#0FDH             ; 9600 baud rate at the frequency of
                                        ; 11.0592MHz
         MOV      SCON,#50H             ; Receiving enabled, 8-bit UART
         MOV      IE,#10010000B         ; UART interrupt enabled
         CLR      TI                    ; Clear transmit flag
         CLR      RI                    ; Clear receive flag
         SETB     TR1                   ; Start Timer1

LOOP:    SJMP     LOOP                  ; Remain here

IR_SER:  JNB      RI,OUTPUT             ; If any data is received,
                                        ; move it to the port
         MOV      A,SBUF                ; P1
         MOV      P1,A
         CLR      RI                    ; Clear receive flag
OUTPUT   RETI

         END                            ; End of program

Data transmission via UART

This program describes how to use UART to transmit data. A sequence of numbers (0-255) is transmitted to a PC at 9600 baud rate. The MAX 232 is used as a voltage regulator.
;************************************************************************
;* PROGRAM NAME : UartS.ASM
;* DESCRIPTION: Sends values 0-255 to PC.
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(UARTS.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;STACK
         DSEG    AT    03FH
STACK_START:     DS    040H

;RESET VECTORS
         CSEG    AT    0
         JMP     XRESET               ; Reset vector

         ORG     100H

XRESET:  MOV     IE,#00               ; All interrupts are disabled
         MOV     SP,#STACK_START      ; Initialization of Stack pointer
         MOV     TMOD,#20H            ; Timer1 in mode 2
         MOV     TH1,#0FDH            ; 9600 baud rate at the frequency of
                                      ; 11.0592MHz
         MOV     SCON,#40H            ; 8-bit UART
         CLR     TI                   ; Clear transmit bit
         CLR     RI                   ; Clear receive flag
         MOV     R3,#00H              ; Reset caunter
         SETB    TR1                  ; Start Timer 1

START:   MOV     SBUF,R3              ; Move number from counter to a PC
LOOP1:   JNB     TI,LOOP1             ; Wait here until byte transmission is
                                      ; complete
         CLR     TI                   ; Clear transmit bit
         INC     R3                   ; Increment the counter value by 1

         CJNE    R3,#00H,START        ; If 255 bytes are not sent return to the
                                      ; label START

LOOP:    SJMP    LOOP                 ; Remain here

         END                          ; End of program

Writing message on LCD display

This example uses the most frequently used type of LCD which displays text in two lines with 16 characters each. In order to save I/O ports, only 4 pins are used for communication here. In this way each byte is transmitted in two steps: first higher then lower nible. LCD needs to be initialized at the beginning of the program. Besides, parts of the program which repeat in the program create special subroutines. All this may seem extremely complicated, but the whole program basically performs several simple operations and displays”Mikroelektronika Razvojni sistemi”. 8051-chapter-06-image-028
*************************************************************************
;* PROGRAM NAME : Lcd.ASM
;* DESCRIPRTION : Program for testing LCD display. 4-bit communication
;* is used. Program does not check BUSY flag but uses program delay 
;* between 2 commands. PORT1 is used for connection
;* to the microcontroller.
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(LCD.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;Stack
          DSEG     AT     0E0h
Stack_Start:       DS     020h

Start_address      EQU    0000h

                                             ;Reset vectors
          CSEG     AT     0
          ORG      Start_address
          JMP      Inic

          ORG      Start_address+100h

          MOV      IE,#00                    ; All interrupts are disabled
          MOV      SP,#Stack_Start

Inic:     CALL     LCD_inic                  ; Initialize LCD

;*************************************************
;* MAIN PROGRAM
;*************************************************

START:    MOV      A,#80h                    ; Next character will appear on the first
          CALL     LCD_status                ; location in the first line of LCD display.
          MOV      A,#'M'                    ; Display character ‘M’.
          CALL     LCD_putc                  ; Call subroutine for character transmission.
          MOV      A,#'i'                    ; Display character ‘i’.
          CALL     LCD_putc
          MOV      A,#'k'                    ; Display character ‘k’.
          CALL     LCD_putc
          MOV      A,#'r'                    ; Display character ‘r’.
          CALL     LCD_putc
          MOV      A,#'o'                    ; Display character ‘o’.
          CALL     LCD_putc
          MOV      A,#'e'                    ; Display character ‘e’.
          CALL     LCD_putc
          MOV      A,#'l'                    ; Display character ‘l’.
          CALL     LCD_putc
          MOV      A,#'e'                    ; Display character ‘e’.
          CALL     LCD_putc
          MOV      A,#'k'                    ; Display character ‘k’.
          CALL     LCD_putc
          MOV      A,#'t'                    ; Display character ‘t’.
          CALL     LCD_putc
          MOV      A,#'r'                    ; Display character ‘r’.
          CALL     LCD_putc
          MOV      A,#'o'                    ; Display character ‘o’.
          CALL     LCD_putc
          MOV      A,#'n'                    ; Display character ‘n’.
          CALL     LCD_putc
          MOV      A,#'i'                    ; Display character ‘i’.
          CALL     LCD_putc
          MOV      A,#'k'                    ; Display character ‘k’.
          CALL     LCD_putc
          MOV      A,#'a'                    ; Display character ‘a’.
          CALL     LCD_putc

          MOV      A,#0c0h                   ; Next character will appear on the first
          CALL     LCD_status                ; location in the second line of LCD display.
          MOV      A,#'R'                    ; Display character ‘R’.
          CALL     LCD_putc                  ; Call subroutine for character transmission.
          MOV      A,#'a'                    ; Display character ‘a’.
          CALL     LCD_putc
          MOV      A,#'z'                    ; Display character ‘z’.
          CALL     LCD_putc
          MOV      A,#'v'                    ; Display character ‘v’.
          CALL     LCD_putc
          MOV      A,#'o'                    ; Display character ‘o’.
          CALL     LCD_putc
          MOV      A,#'j'                    ; Display character ‘j’.
          CALL     LCD_putc
          MOV      A,#'n'                    ; Display character ‘n’.
          CALL     LCD_putc
          MOV      A,#'i'                    ; Display character ‘i’.
          CALL     LCD_putc
          MOV      A,#' '                    ; Display character ‘ ’.
          CALL     LCD_putc
          MOV      A,#'s'                    ; Display character ‘s’.
          CALL     LCD_putc
          MOV      A,#'i'                    ; Display character ‘i’.
          CALL     LCD_putc
          MOV      A,#'s'                    ; Display character ‘s’.
          CALL     LCD_putc
          MOV      A,#'t'                    ; Display character ‘t’.
          CALL     LCD_putc
          MOV      A,#'e'                    ; Display character ‘e’.
          CALL     LCD_putc
          MOV      A,#'m'                    ; Display character ‘m’.
          CALL     LCD_putc
          MOV      A,#'i'                    ; Display character ‘i’.
          CALL     LCD_putc

          MOV      R0,#20d                   ; Wait time (20x10ms)
          CALL     Delay_10ms                ;
          MOV      DPTR,#LCD_DB              ; Clear display
          MOV      A,#6d                     ;
          CALL     LCD_inic_status           ;
          MOV      R0,#10d                   ; Wait time(10x10ms)
          CALL     Delay_10ms
          JMP      START

;*********************************************
;* Subroutine for wait time (T= r0 x 10ms)
;*********************************************

Delay_10ms:  MOV   R5,00h                    ; 1+(1+(1+2*r7+2)*r6+2)*r5 approximately
             MOV   R6,#100d                  ; (if r7>10)
             MOV   R7,#100d                  ; 2*r5*r6*r7
             DJNZ  R7,$                      ; $ indicates current instruction.
             DJNZ  R6,$-4
             DJNZ  R5,$-6
             RET

;**************************************************************************************
;* SUBROUTINE: LCD_inic
;* DESCRIPTION: Subroutine for LCD initialization.
;*
;* (is used with 4-bit interface, under condition that pins DB4-7 on LCD
;* are connected to pins PX.4-7 on microcontroller’s ports, i.e. four higher
;* bits on the port are used).
;*
;* NOTE: It is necessary to define port pins for controlling LCD operation:
;* LCD_enable, LCD_read_write, LCD_reg_select,similar to port for connection to LCD.
;* It is also necessary to define addresses for the first character in each
;* line.
;**************************************************************************************

LCD_enable     BIT    P1.3                   ; Bit for activating pin E on LCD.
LCD_read_write BIT    P1.1                   ; Bit for activating pin RW on LCD.
LCD_reg_select BIT    P1.2                   ; Bit for activating pin RS on LCD.
LCD_port       SET    P1                     ; Port for connection to LCD.
Busy           BIT    P1.7                   ; Port pin on which Busy flag appears.

LCD_Start_I_red  EQU   00h                   ; Address of the first message character
                                             ; in the first line of LCD display.
LCD_Start_II_red EQU   40h                   ; Address of the first message character
                                             ; in the second line of LCD display.

LCD_DB:        DB     00111100b              ; 0 -8b, 2/1 lines, 5x10/5x7 format
               DB     00101100b              ; 1 -4b, 2/1 lines, 5x10/5x7 format
               DB     00011000b              ; 2 -Display/cursor shift, right/left
               DB     00001100b              ; 3 -Display ON, cursor OFF, cursor blink off
               DB     00000110b              ; 4 -Increment mode, display shift off
               DB     00000010b              ; 5 -Display/cursor home
               DB     00000001b              ; 6 -Clear display
               DB     00001000b              ; 7 -Display OFF, cursor OFF, cursor blink off

LCD_inic:                                    ;*****************************************

               MOV    DPTR,#LCD_DB

               MOV    A,#00d                 ; Triple initialization in 8-bit
               CALL  LCD_inic_status_8       ; mode is performed at the beginning
               MOV   A,#00d                  ; (in case of slow increment of
               CALL  LCD_inic_status_8       ; power supply when the power supply is on
               MOV   A,#00d
               lcall LCD_inic_status_8

               MOV   A,#1d                   ; Change from 8-bit into
               CALL  LCD_inic_status_8       ; 4-bit mode
               MOV   A,#1d
               CALL  LCD_inic_status

               MOV   A,#3d                   ; As from this point the program executes in
                                             ;4-bit mode
               CALL  LCD_inic_status
               MOV   A,#6d
               CALL  LCD_inic_status
               MOV   A,#4d
               CALL  LCD_inic_status

               RET

LCD_inic_status_8:
                                             ;******************************************
               PUSH  B

               MOVC  A,@A+DPTR
               CLR   LCD_reg_select          ; RS=0 - Write command
               CLR   LCD_read_write          ; R/W=0 - Write data on LCD

               MOV   B,LCD_port              ; Lower 4 bits from LCD port are memorized
               ORL   B,#11110000b
               ORL   A,#00001111b
               ANL   A,B

               MOV   LCD_port,A              ; Data is moved from A to LCD port
               SETB  LCD_enable              ; high-to-low transition signal
                                             ; is generated on the LCD's EN pin
               CLR   LCD_enable               

               MOV   B,#255d                 ; Time delay in case of improper reset
               DJNZ  B,$                     ; during initialization
               DJNZ B,$
               DJNZ B,$

               POP B
               RET

LCD_inic_status:
;****************************************************************************
               MOVC  A,@A+DPTR
               CALL  LCD_status
               RET

;****************************************************************************
;* SUBROUTINE: LCD_status
;* DESCRIPTION: Subroutine for defining LCD status.
;****************************************************************************

LCD_status:    PUSH  B
               MOV   B,#255d
               DJNZ  B,$
               DJNZ  B,$
               DJNZ  B,$
               CLR   LCD_reg_select          ; RS=O: Command is sent to LCD
               CALL  LCD_port_out

               SWAP  A                       ; Nibles are swapped in accumulator

               DJNZ  B,$
               DJNZ  B,$
               DJNZ  B,$
               CLR   LCD_reg_select          ; RS=0: Command is sent to LCD
               CALL  LCD_port_out

               POP   B
               RET

;****************************************************************************
;* SUBROUTINE: LCD_putc
;* DESCRIPTION: Sending character to be displayed on LCD.
;****************************************************************************

LCD_putc:      PUSH  B
               MOV   B,#255d
               DJNZ  B,$
               SETB  LCD_reg_select          ; RS=1: Character is sent to LCD
               CALL  LCD_port_out

               SWAP  A                       ; Nibles are swapped in accumulator

               DJNZ  B,$
               SETB  LCD_reg_select          ; RS=1: Character is sent to LCD

               CALL  LCD_port_out
               POP   B
               RET

;****************************************************************************
;* SUBROUTINE: LCD_port_out
;* DESCRIPTION: Sending commands or characters on LCD display
;****************************************************************************

LCD_port_out:  PUSH  ACC
               PUSH  B
               MOV   B,LCD_port              ; Lower 4 bits of LCD port are memorized
               ORL   B,#11110000b
               ORL   A,#00001111b
               ANL   A,B

               MOV   LCD_port,A              ; Data is copied from A to LCD port

               SETB  LCD_enable              ; high-to-low transition signal
                                             ; is generated on the LCD's EN pin
               CLR   LCD_enable               

               POP   B
               POP   ACC
               RET

               END                           ; End of program

Binary to decimal number conversion

When using LED and LCD displays, it is often necessary to convert numbers from binary to decimal. For example, if some register contains a number in binary format that should be displayed on a three digit LED display it is first necessary to convert it to decimal format. In other words, it is necessary to define what should be displayed on the most right display (units), middle display (tens) and most left display (hundreds). The subroutine below performs conversion of one byte. Binary number is stored in the accumulator, while digits of that number in decimal format are stored in registers R3, R2 and accumulator (units, tens and hundreds, respectively).
;************************************************************************
;* SUBROUTINE NAME : BinDec.ASM
;* DESCRIPTION : Content of accumulator is converted into three decimal digits
;************************************************************************

BINDEC:            MOV     B,#10d         ; Store decimal number 10 in B
                   DIV     AB             ; A:B. Remainder remains in B
                   MOV     R3,B           ; Move units to register R3
                   MOV     B,#10d         ; Store decimal number 10 in B
                   DIV     AB             ; A:B. Remainder remains in B
                   MOV     R2,B           ; Move tens to register R2
                   MOV     B,#10d         ; Store decimal number 10 in B
                   DIV     AB             ; A:B. Remainder remains in B
                   MOV     A,B            ; Move hundreds to accumulator
                   RET                    ; Return to the main program

MIKROE

MIKROE is a development tools company dedicated to standardization and time-saving in the embedded industry.

  • About us
  • Success story
  • Contact
  • PressKit
  • Timeline
  • Partners
  • Legal
  • Distributors
  • Legacy Products

SOLUTIONS

  • Click boards™
  • Development boards
  • Mikromedia
  • CODEGRIP
  • NECTO Studio
  • Planet Debug
  • ClickID
  • Click Snap
  • EmbeddedWiki

SUPPORT

  • Helpdesk
  • Forum
  • Libstock
  • Learn
  • Let's Make
  • eBooks
  • Premium TS
  • Design service
  • Product Customization
  • Contract Manufacturing

STANDARD

  • mikroBUS™
  • mikroSDK
  • SiBRAIN
  • DISCON

Prodavnica za inostrano tržište

Nalazite se na prodavnici za inostrano tržište. Da li želite da Vas odvedemo na prodavnicu koja je namenjena za Srbiju?

Prodavnica za inostrano tržište

Nalazite se na prodavnici za inostrano tržište. Da li želite da Vas odvedemo na prodavnicu koja je namenjena za Srbiju?

Daily product releases, special offers, and more

  • FOLLOW US:

  • instagram
  • linkedin
  • facebook
  • github
  • newsletter
  • youtube
  • twitter twitter

Join us

Pridruži nam se

Careers
Internship
Posao
Napravi Click
Praksa
Copyright© 2025 MikroElektronika d.o.o.

Privacy