ATmega16 controls MAX7219 to drive digital tube

Publisher:幸福如意Latest update time:2018-05-29 Source: eefocusKeywords:ATmega16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

ATmega16 controls MAX7219 to drive digital tubes, and provides source code, schematics, welding diagrams, etc. See the end of the article for links. 
Write the picture description here

Write the picture description here

Schematic

Write the picture description here

Source code

MAX7219.H

/**********************************************************

* File name: MAX7219.H 

* Description: MAX7219 driver package program 

**********************************************************/

#ifndef _MAX7219_H_

#define _MAX7219_H_


#include

#include


//Function register macro definition

#define DECODEMODE 0X09 //Decoding control register address

#define INTENSITY 0X0A //Brightness control register address

#define SCANLIMIT 0X0B //Scan limit register address

#define SHUTDOWN 0X0C //Shutdown mode register address

#define DISPTEST 0X0F //Test control register address

// External callable function definition

void MAX7219_Write(unsigned char addr, unsigned char dat);

void MAX719_Init(void);


#endif



MAX7219.C


/**********************************************************

* File name: MAX7219.c 

* Description: MAX7219 driver package program 

**********************************************************/


#include "max7219.h"


/**************************************************************

** Function name: void SPI_Init(void) 

** Function description: SPI initialization

** Input: None

** Global variables: None

** Calling module: None

** illustrate:

** Note:

**************************************************************/

void SPI_Init(void) 

{

    DDRB=0xB0; //Select 7219

    SPCR=0x51; //spi settings

}

/**************************************************************

** Function name: void MAX7219_WriteByte(unsigned char date)

** Function description: Write a byte to MAX7219

** Input: unsigned char date byte content

** Global variables: None

** Calling module: None

** illustrate:

** Note:

**************************************************************/

void MAX7219_WriteByte(unsigned char date)

{

    SPDR = date; /* Start data transfer */

    while (!(SPSR & (1<

}

/**************************************************************

** Function name: void MAX7219_Write(unsigned char addr, unsigned char dat)

** Function description: Write instructions to MAX7219

** Input: unsigned char addr address 

             unsigned char dat data

** Global variables: None

** Calling module: None

** illustrate:

** Note:

**************************************************************/

void MAX7219_Write(unsigned char addr, unsigned char dat)

{

     PORTB = 0X00;

     MAX7219_WriteByte(addr); //Select register address

     MAX7219_WriteByte(dat); //Select the chip to execute the command

     PORTB = 0X10;

}


/**************************************************************

** Function name: void MAX7219_Init(void)  

** Function description: MAX7219 initialization

** Input: None

** Global variables: None

** Calling module: None

** illustrate:

** Note:

**************************************************************/

void MAX7219_Init(void)      

    SPI_Init(); //SPI function initialization

    MAX7219_Write(SHUTDOWN, 0x01); //Shutdown mode register; shutdown state, the lowest bit D0 = 0; normal state, the lowest bit D0 = 1

    MAX7219_Write(DISPTEST, 0x00); //Display test register; in test state, the lowest bit D0 = 1, all bits are displayed brightly; in normal working state, the lowest bit D0 = 1

    MAX7219_Write(DECODEMODE, 0xff); //decoding control register; 0XFF, full decoding

    MAX7219_Write(SCANLIMIT, 0x07); //Scan limit register; set the number of LEDs to be displayed (1~8). If it is set to 0xX4, LEDs 0~5 will be displayed.

    MAX7219_Write(INTENSITY, 0x08); //Brightness control register; there are 16 levels to choose from, used to set the display brightness of the LED, 0X00-0X0F

}


Keywords:ATmega16 Reference address:ATmega16 controls MAX7219 to drive digital tube

Previous article:ICCAVR compilation error! E(197): area 'bss' not large enough
Next article:AVR microcontroller (ATMEGA16) DA0832 chip D/A conversion

Recommended ReadingLatest update time:2024-11-16 14:38

AVR atmega16 frequency meter using input capture function
  /******************************************** * Program design based on frequency meter * * Function: frequency meter * * Clock frequency: internal 8M *         Maximum frequency range of frequency meter. Proteus measured about 65K MADE BY LYQ *****************************************/ #include iom
[Microcontroller]
AVR atmega16 frequency meter using input capture function
ATmega16 drives ds12c887 and displays on lcd1602
#include iom16v.h #include macros.h #define uchar unsigned char #define uint unsigned int #define DS_ PORTC&=~BIT(6) #define DS PORTC|=BIT(6) #define RW_ PORTC&=~BIT(5) #define RW PORTC|=BIT(5) #define AS_ PORTC&=~BIT(4) #define AS PORTC|=BIT(4) #define CS_ PORTC&=~BIT(3) #define CS PORTC|=BIT(3) uchar tab1 ={"DAT:"};
[Microcontroller]
My DIY infrared half-duplex communication handheld handheld
When using a microcontroller to make some small things, due to limited space or limited IO ports of the microcontroller, you don't want to use a display screen. So how do you know the operating status of the microcontroller? This production realizes two-way transmission and reception between ATMEGA16 and ATMEGA8 throug
[Microcontroller]
My DIY infrared half-duplex communication handheld handheld
ATmega16 crystal oscillator
XTAL1 and XTAL2 are used as the input and output of the inverting amplifier of the on-chip oscillator, as shown in Figure 12. This oscillator can use a quartz crystal or a ceramic resonator. The fuse CKOPT is used to select one of the two amplifier modes. When CKOPT is programmed, the oscillator produces full amplitu
[Microcontroller]
ATmega16 crystal oscillator
Atmega 16 button usage
#include #include #define uchar unsigned char #define uint unsigned int void init() {  DDRD&=~(_BV(PD4)|_BV(PD5)|_BV(PD6)|_BV(PD7)); //The upper four bits of the PD port are input, connected to the button  DDRB|=_BV(PB4)|_BV(PB5)|_BV(PB6)|_BV(PB7); //The upper four bits of the PB port are output, connected to
[Microcontroller]
ATmega16 reset and interrupt handling
AVR has different interrupt sources. Each interrupt and reset has an independent interrupt vector in the program space. All interrupt events have their own enable bit. When the enable bit is set and the global interrupt enable bit I of the status register is also set, an interrupt can occur. Depending on the program c
[Microcontroller]
ATMEGA16 read and write 24C02 C51 program
Complete code download address: http://www.51hei.com/f/2402avr.rar main function: /* Program function: ATMEGA16 read and write 24C02 Author: Zhu Bo Date: January 30, 2012 Note: After the program is run, it will automatically count from 0 to 256 (the result of byte operation) When reset or power
[Microcontroller]
ATMEGA16 read and write 24C02 C51 program
Design scheme of controller for single-phase fire emergency power supply system
Introduction The modernization of social life has put higher and higher demands on power supply. Many large buildings, especially public buildings and facilities such as airports, highways, tunnels, shopping malls, office buildings, exhibition centers, etc., will have many unexpected situations once the powe
[Power Management]
Design scheme of controller for single-phase fire emergency power supply system
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号