B001-Atmega16-digital tube

Publisher:BlossomJoyLatest update time:2022-01-12 Source: eefocusKeywords:Atmega16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

// Enable digital tubes No. 0 to No. 7 respectively (use AND (&) to enable)

static const uint8_t segment_index[8]= { 0,1,2,3,4,5,6,7 };

 

typedef struct 

{

    uint8_t *seg_index; //bit select port data

    uint8_t *seg_code; //Segment selection port data

    uint8_t index; // Enable the index digital tube

    uint8_t data_part[_countof(segment_index)]; // 8 data sent to the digital tube [0:7] for display

    uint32_t data; // Data for display, it will be split into data_part[] for storage

}T_SEG_LED_DISPLAY_CTRL,*pT_SEG_LED_DISPLAY_CTRL;

 

static T_SEG_LED_DISPLAY_CTRL LED_display_ctrl = {  .seg_index = (uint8_t *)(&PORTA),

                                                    .seg_code = (uint8_t *)(&PORTB),

                                                    .index = 0,

                                                    .data_part = { 0,0,0,0,0,0,0,0 },

                                                    .data = 0

                                                  };

static pT_SEG_LED_DISPLAY_CTRL p_LED_display_ctrl = &LED_display_ctrl;

 

// ==========================================================================================================

//LED digital tube hardware initialization

// 

// ==========================================================================================================

void Mod_LED_display_init(void)

{

    // Digital tube bit selection enable (74HC138 chip enable): output high level

    DDRC  |= (IO_OUTPUT << DDC7);

    PORTC |= (IO_OUTPUT << PC7 );

    // Segment selection control: PORTB is initialized to: output low level

    DDRB  = 0xFF;

    PORTB = 0x00;

    // Bit selection control: PORTA[2:0] is initialized to: output low level (select the 0th digital tube)

    DDRA  |=   (IO_OUTPUT << DDA0) |(IO_OUTPUT << DDA1) | (IO_OUTPUT << DDA2);

    PORTA &= ~((1 << PA0 ) |(1 << PA1 ) | (1 << PA2 ));

}

 

// ==========================================================================================================

// Refresh the LED digital tube display data

// 

// Parameter: static index Split an 8-digit decimal number into 8 cells of the array, index is the subscript of the current array element

// Split only 1 bit at a time, the part of the data exceeding 8 bits will be automatically truncated

// 

// Query message: EVENT_SEG_UPDATE

// Message parameter: 32-bit value

// Send message: None

// 

// illustrate:

// (0). Refresh regularly in the system timer or task scheduler (scheduled as a task)

// (1). An 8-digit number needs to be split. Each split (plus refresh display) takes 170us (including the time to enter and exit the task function)

// (2). In fact, every time data is updated, the value in the 8-bit array p_LED_display_ctrl->data_part needs to be recalculated

// (3). If data is a 3-digit number (such as 120), it only needs to be calculated 3 times, which means 3 calculations will take about 170us.

// After data=0, no time-consuming calculation is performed, but the corresponding element in the array p_LED_display_ctrl->data_part is directly assigned a value of 0.

// (4). If data is 0 or has not changed, no calculation is required. In this case, this task function takes 11.32us

// 

// ==========================================================================================================

void task_Mod_LED_display_update(void)

{

    uint8_t temp = 0;

    volatile static uint8_t index = _countof(segment_index);

 

    // --------------------------------------------------------------------

    // Query message

    if(TRUE == sys_event_peek(EVENT_SEG_UPDATE, &p_LED_display_ctrl->data))

    {

        index = 0; // If updated data is obtained, data splitting will be started

    }

 

    // ---------------------------------------------------

    // Main text

    // ---------------------------------------------------

    // Split 8-bit decimal data into data_part[] (starting from data position 0)

    if(index < _countof(segment_index))

    {

        if(0 == p_LED_display_ctrl->data) { temp = 0; }

        else                              { temp = p_LED_display_ctrl->data % 10UL; }

 

        p_LED_display_ctrl->data_part[_countof(segment_index) - 1 - index] = temp;

 

        if(0 != p_LED_display_ctrl->data) { p_LED_display_ctrl->data = p_LED_display_ctrl->data / 10UL; }

 

        index++;

    }

 

    // --------

    // Refresh the display

    // Turn off the current digital tube

    *p_LED_display_ctrl->seg_code = segment_code[_countof(segment_code) - 1];

 

    // Switch to the next digital tube

    p_LED_display_ctrl->index++;

    if(p_LED_display_ctrl->index > (_countof(segment_index) - 1))

    {

        p_LED_display_ctrl->index = 0;

    }

    // Modify bit selection and display

    *p_LED_display_ctrl->seg_index |= segment_index[_countof(segment_index) - 1];

    *p_LED_display_ctrl->seg_index &= segment_index[p_LED_display_ctrl->index];

    *p_LED_display_ctrl->seg_code   = segment_code[p_LED_display_ctrl->data_part[segment_index[p_LED_display_ctrl->index]]];

 

    // ---------------------------------------------------

    // Send a message

}

 

// ==========================================================================================================

//LED digital tube display (decimal)

// 

// illustrate:

// (1): If necessary, the display format can be made into event EVENT_SEG_FORMAT with message: MSG_SEG_HEX (display the result in hexadecimal)

// MSG_SEG_DEC (display the result in decimal)

// MSG_SEG_OCT (display the result in octal)

// MSG_SEG_BIN (display the result in binary)

// 

// ==========================================================================================================

void Mod_LED_display(uint32_t data)

{

    sys_event_post(EVENT_SEG_UPDATE, data);

}

For details on message management and task scheduling, see: "A005-Software Structure-From Front-end and Back-end to Scheduler".




-------------------------------------------------------------------------------------------------------------------------------------

Step 6: Display in the specified base

Improve:

1. You can specify to display data from binary to hexadecimal

2. Further organize the task functions under the message mechanism


Drv_Sys.c:

// ==========================================================================================================

// Set the data format (range: [2,16])

// 

// ==========================================================================================================

void Drv_sys_set_digital_format(uint8_t format)

{

    if((format >= 2) && (format <= 16))

    {

        sys_event_post(EVENT_DIGITAL_FORMAT, format);

    }

}

Mod_LED_display.c:

// ==========================================================================================================

// Copyright (c) 2016 Manon.C

// 

// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 

// associated documentation files (the "Software"), to deal in the Software without restriction, including 

// without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 

// sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject 

// to the following conditions:

// 

// The above copyright notice and this permission notice shall be included in 

// all copies or substantial portions of the Software.

// 

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 

// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 

// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 

// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 

// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// 

// ------------------------------------

// This article defines the 8-segment LED digital tube driver under Atmega16

// The corresponding driving circuit in the article: http://blog.csdn.net/manon_des_source/article/details/51783675

// 

// ------------------------------------

// Include:

// 

// ==========================================================================================================

#include "Mod_LED_Displayer.h"

 

// Segment code (common cathode == high level lights up)

static const uint8_t segment_code[17]=

{

    0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,  // 0 - 9

    0x77,0x7c,0x39,0x5e,0x79,0x71, // A - F (AND with it to get the value of a certain 1-digit digital tube)

    0x00 // All off (or with it to extinguish the display of the currently selected digital tube)

};

 

// Bit code (low level enable) (use 74HC138 strobe bit selection)

// Enable digital tubes No. 0 to No. 7 respectively (use AND (&) to enable)

static const uint8_t segment_index[8]= { 0,1,2,3,4,5,6,7 };

 

typedef struct 

{

    uint8_t *seg_index; //bit select port data

    uint8_t *seg_code; //Segment selection port data

    uint8_t index; // Enable the index digital tube

 

    uint8_t format; //Data display format, range: [2,16]

    uint8_t set_format; // Need to set a new display format

    uint8_t set_data; // There is new display data

    uint8_t data_part[_countof(segment_index)]; // 8 data sent to the digital tube [0:7] for display

    uint8_t data_index; // When splitting data into data_part[], it is used as the index of data_part

    uint32_t data; // Data for display, it will be split into data_part[] for storage

    uint32_t data_copy; // Needed for data backup and format reset

}T_SEG_LED_DISPLAY_CTRL,*pT_SEG_LED_DISPLAY_CTRL;

 

static T_SEG_LED_DISPLAY_CTRL LED_display_ctrl = {  .seg_index = (uint8_t *)(&PORTA),

                                                    .seg_code = (uint8_t *)(&PORTB),

                                                    .index = 0,

 

                                                    .format = 10, // Display in decimal format by default

                                                    .set_format = FALSE,

                                                    .set_data   = FALSE,

[1] [2] [3] [4] [5]
Keywords:Atmega16 Reference address:B001-Atmega16-digital tube

Previous article:Atmega16 - BSP and Task List
Next article:A005-Software Structure-From Frontend and Backend to Scheduler

Recommended ReadingLatest update time:2024-11-17 11:57

Design of dry-type transformer intelligent controller system using ATmega16 microcontroller
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 tra
[Microcontroller]
Design of dry-type transformer intelligent controller system using ATmega16 microcontroller
ADC acquisition digital tube display simulation program based on AVR microcontroller Atmega16
Circuit Diagram The digital tube used is 7SEG-MPX4-CC. code #include mega16.h #include delay.h #define uchar unsigned char #define uint unsigned int flash char led_7 = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; flash char position = {0xe0, 0xd0, 0xb0, 0xf0}; char ad ; //Digital tube displ
[Microcontroller]
ADC acquisition digital tube display simulation program based on AVR microcontroller Atmega16
ATmega16 External Reset
External reset is generated by a low level applied to the RESET pin. When the reset low level duration is greater than the minimum pulse width (see Table 15), the reset process is triggered, even if there is no clock signal running at this time. When the external signal reaches the reset threshold voltage VRST (rising
[Microcontroller]
ATmega16 External Reset
AVR microcontroller (ATMEGA16) controls the buzzer
#include iom16v.h    #include macros.h    #define uchar unsigned char   #define uint unsigned int   #define DELAY 500   void delay(uint z)    //1ms   {    uint x,y;    for(x=z;x 0;x--)     for(y=157;y 0;y--);   }   void main(void)   {    DDRA |=BIT(0);    while(1)    {     PORTA &=~BIT(0);     delay(
[Microcontroller]
AVR microcontroller (ATMEGA16) controls the buzzer
ATmega16 Status Register
The status register contains information about the results of the most recently executed arithmetic instruction. This information can be used to change the program flow to implement conditional operations. As described in the instruction set, all ALU operations will affect the contents of the status register. This eli
[Microcontroller]
ATmega16 Status Register
AVR simple ADC program
I recently looked at the ADC of ATmega16 and wrote this simple program to understand the simple control of ADC. The program is simulated with Proteus, using the ICCAVR7 compiler (the header files are different, so you should consider it yourself) The program content is: read the external voltage through PA1 and dynami
[Microcontroller]
Design of remote control password lock system based on GSM network
This paper introduces the specific design of the hardware and program implementation process of the GSM-based single-chip remote control password lock. The AVR single-chip ATMEGA16 is used as the controller. On the basis of realizing the password keyboard input opening control of the electronic lock, LCD serial display
[Microcontroller]
Design of remote control password lock system based on GSM network
ATMEGA16 ADC analog-to-digital conversion example program
ATMEGA16 ADC analog-to-digital conversion example program 1. Development Language            This example is developed using WinAVR/GCC 20050214  version       2. Example Description          This program simply demonstrates how to use the ADC analog-to-digital converter of ATMEGA16            Ordinary single-ended in
[Microcontroller]
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号