atmega16 controls MAX7219 in digital tube display

Publisher:RadiantExplorerLatest update time:2016-01-19 Source: eefocusKeywords:atmega16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include

#include

#define uchar unsigned char
#define uint unsigned int

uchar QIAN=0,BAI=0,SHI=0,GE=0;

void delay_ms(uint ms)
{
  uint i,j;
  for(i=ms;i>0;i--)
     for(j=1141;j>0;j--);
}


void System_Init(void)
{
  DDRB=0XFF;
  PORTB=0XFF;
}

void BCD_Change(uint data)

  uint TEN=0;        //Note the type of variable
  TEN=data;
  QIAN=TEN/1000;       //0x03e8=1000
  TEN% =1000;
  BAI=TEN/100;
  TEN%=100;
  SHI=TEN/10;
  TEN%=10;
  GE=TEN;
}

void MAX7219_SendData(uchar addr,uchar data)//Send the high bit first and then the low bit
{
  uchar i =0,j=0,a=0,temp=0;
  PORTB&=0Xbf;     //Pull LOAD low
  while(i<16)//LOAD/cs terminal at the same time or after the rising edge of the 16th clock, the next It becomes high level before the rising edge of the clock, otherwise the data will be lost
  {
     if(i<8)        //Determine whether to transmit the address or the data
        temp=addr;
     else
        temp=data;
     for(j=8;j>=1; j--)
     {
        a=temp;     
  a=a>>2;   //Shift the data to the right by 2, and shift the highest bit of the data to be transmitted to bit5 to facilitate the output
  of a=a&0x20;  //Remove it on the PB5 port The high and low bits of the data on BIT5
  PORTB&=0XDF;   //0XDF   1101 1111
  PORTB|=a;  //Output the highest bit of the data
  temp<<=1;       //Shift the data to the left by one bit and transmit the second highest bit of data, one cycle 8 transmissions completed
  PORTB&=0x7f;   //Pull CLK low
  PORTB|=0x80;   //Pull CLK high, data transmission on rising edge
     }
     i+=8;            //Judgment statement
  }
  PORTB|=0X40;   //LOAD=1,PB6 =1;
}

void MAX7219_SendData_(uchar addr,uchar data)
{
  uchar i=0,j=0,temp=0;
  PORTB&=0XBF;     //LOAD=0, PB6=0;
  for(i=0;i<8 ;i++)  //Transfer address
  {
     temp=addr;
     PORTB&=0X7F;   //SLK=0, data is transferred in on the rising edge of the clock
     if((temp&0x80)==0x80) //Determine whether the high bit is 1 or 0, if it is 1 Output 1 on PB7, otherwise output 0
     PORTB|=0X20;
     else
     PORTB&=0XDF;
  PORTB|=0X80;   //SLK=1, data is transferred in on the rising edge of the clock
  addr=addr<<1;   //The data is shifted left by one bit, transmit the second-highest data, and complete the transmission 8 times in one cycle
  }
  for(j=0;j<8;j++)  //Transmit data
  {
     temp=data;
     PORTB&=0X7F;    //SLK=0, data is on the rising edge of the clock Pass in
     if((temp&0x80)==0x80)//Determine whether the high bit is 1 or 0, if it is 1, output 1 on PB7, otherwise output 0
     PORTB|=0X20;
     else
     PORTB&=0XDF;
  PORTB|=0X80;  //SLK =1, data is transferred in at the rising edge of the clock
  data=data<<1;      //The data is shifted one bit to the left, the next highest bit data is transferred, and the transfer is completed 8 times in one cycle
  }
  PORTB|=0X40;   //LOAD=1,PB6= 1;
}

void MAX7219_Init(void)
{
  MAX7219_SendData_(0x0c,0x01);//Power-down mode: 0x01 indicates normal operation/0x00 indicates sleep mode
  MAX7219_SendData_(0x0f,0x00);//Display test mode: 0x00 indicates normal operation/0x01 Indicates display test mode
  MAX7219_SendData_(0x09,0xff);//Decoding mode: 0x00 means no decoding/0x01, 0x0f, 0xff means different decoding methods, 0xff means 7-segment decoding
  MAX7219_SendData_(0x0b,0x07);// Scan settings: 0x07 represents 8 digital tubes
  MAX7219_SendData_(0x0a,0x07); //Display brightness: the range is 0~f, here it is set to 7
}

void Display_time(void)
{
   MAX7219_SendData_(0x01,1);
 MAX7219_SendData_(0x02,1);
 MAX7219_SendData_(0x03,0x0a);
 MAX7219_SendData_(0x04,2);
 MAX7219_SendData_(0x05,6);
 MAX7219_SendData_ (0x06,0x0a);
 MAX7219_SendData_( 0x07,3);
 MAX7219_SendData_(0x08,0);
}

void Display_date(void)
{
  
  MAX7219_SendData(0x01,QIAN);
  MAX7219_SendData(0x02,BAI);
  MAX7219_SendData(0x03,SHI);
  MAX7219_SendData(0x04,0X80|GE );
  MAX7219_SendData (0x05,1);
  MAX7219_SendData(0x06,0x80|2);
  MAX7219_SendData(0x07,2);
  MAX7219_SendData(0x08,8);
}

void main(void)
{
  System_Init();
  MAX7219_Init();
  BCD_Change(2010);
  while (1)
  {
     Display_time();
  delay_ms(2000);
  Display_date();
  delay_ms(2000);
  }
}

PROTUES7.5 policy map

Keywords:atmega16 Reference address:atmega16 controls MAX7219 in digital tube display

Previous article:ATMEGA16 four-line driver LCD display time-DS1302
Next article:ATMEGA16 reads and writes 24C02 via TWI

Recommended ReadingLatest update time:2024-11-17 03:01

Design of Intelligent Temperature Controller for Dry-Type Transformer Based on ATmega16 Single Chip Microcomputer
1 Working Principle The temperature controller consists of three parts: temperature monitoring, signal processing, and output control. The system block diagram is shown in Figure 1. It obtains the winding temperature value through three platinum resistance sensors embedded in the three-phase winding of the trans
[Microcontroller]
Design of Intelligent Temperature Controller for Dry-Type Transformer Based on ATmega16 Single Chip Microcomputer
STC12 hardware SPI drives MAX7219 dot matrix LED
max7219 is a driver chip for driving 8-bit 7-segment digital LED or 8x8 dot matrix LED. It uses 16 pins to manage 64 light points in a column scan mode. The refresh rate is 500-1300Hz when displaying 8 digits, and the typical value is 800Hz. Pin Function DIG0 - DIG7: These 8 pins represent a 7-segment number + a dot
[Microcontroller]
Design of remote temperature difference cycle controller based on ATmega16
This design uses AVR microcontroller, RS 485 technology and NTC thermistor technology to develop the remote temperature difference cycle controller. 1 System structure and working principle The remote temperature difference cycle controller is mainly used to measure and display the water temperature of the water
[Microcontroller]
Design of remote temperature difference cycle controller based on ATmega16
ATmega16 Development Board Tutorial (1) - LED Lighting
2. LED lights up When used as a general digital IO, the IO of the AVR microcontroller has read, write and modify functions. Each port has 3 registers: DDRx, PORTx, and PINx. DDRx: 1-output, 0-input. When configured as input, PORTx=1, pull-up enabled, PORTx=0, high configuration; when configured as output, PORTx=1, o
[Microcontroller]
ATmega16 Development Board Tutorial (1) - LED Lighting
B001-Atmega16-Interrupt (GCC-AVR)-(ques=3)
Compiler: AVR Studio 4.19 + avr-toolchain-installer-3.4.1.1195-win32.win32.x86 Chip model: ATmega16 Chip frequency: 8MHz ------------------------------------------------------------------------------------------------------------------------------------- Number of open issues = 3 --------------------------------
[Microcontroller]
B001-Atmega16-Interrupt (GCC-AVR)-(ques=3)
ATMEGA16 and DS18B20 digital tube display
A DS18B20 with a large error value caused me a lot of trouble. I always thought it was a program error, so I changed it and it worked! It took me three days to check the program /*This program is an eight-bit common cathode digital tube with two 573 controlled dynamic scans*/ #include iom16v.h #include macros.h #
[Microcontroller]
Design of digital optical power meter based on ATmega16
0 Introduction Digital optical power meter is a portable instrument controlled by a single-chip microcomputer that can measure the strength of optical signals. It is an important instrument used in laying fiber-optic communication trunk lines, equipment maintenance, scientific research and production. Howeve
[Microcontroller]
Design of digital optical power meter based on ATmega16
MAX7219 Data Multiplexer Adds Cursor Functionality to LEDs
A converter is a device that converts one signal into another. A signal is a form or carrier of information. In automated instrumentation and automatic control systems, one signal is often converted into another signal that is compared with a standard or reference quantity in order to connect the two types of instru
[Analog Electronics]
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号