Defining unions and structures in c51

Publisher:YuexiangLatest update time:2016-11-07 Source: eefocusKeywords:c51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Consortium

union {
  unsigned char Ch; //"unsigned number
  unsigned char CHR[4]; //"unsigned array
  unsigned long I; //"unsigned integer
  long L; //"signed long integer
  float F; //"floating point number
    }EEP;

 

float shu;

 EEP.F =shu;        //

 

Structure

struct realti
 {
    uchar Second;
   uchar Minute;
   uchar Hour;
    uchar Day;
    uchar Month;
    uchar Week;
    uchar Year;
  uchar kzz; //8 bytes must be written continuously, otherwise it cannot be written
 };
 struct realti RealTime; //struct realti RealTime[3];

 

or:

struct realti
 {
    uchar Second;
   uchar Minute;
   uchar Hour;
    uchar Day;
    uchar Month;
    uchar Week;
    uchar Year;
  uchar kzz; //8 bytes must be written continuously, otherwise it cannot be written
 }RealTime; //RealTime[3];
 or:

 

struct {
    uchar Second;
   uchar Minute;
   uchar Hour;
    uchar Day;
    uchar Month;
    uchar Week;
    uchar Year;
  uchar kzz; // Continuous writing must be 8 bytes, otherwise it cannot be written
 }RealTime; // RealTime[3];

 

 

usage:

RealTime.Second = 0X30;
      RealTime.Minute = 0X11;
      RealTime.Hour = 0X15;
       RealTime.Day = 0X06;
       RealTime.Month = 0X03;
       RealTime.Week = 0X05;
     RealTime.Year = 0X09;
     RealTime.kzz = 0X00;
     DS1302Write_Time(&RealTime.Second); //Write clock data to DS1302 (multi-byte mode)

DS1302Read_Time(&RealTime.Second); //Read the first address of DS1302 clock data RealTime.Second

void DS1302Read_Time(uchar *pSecDa) //Read DS1302 clock data
{
  uchar i;
  DS1302_Open();//Open DS1302
  DS1302_Write(0xbf); /* 0xbf: clock multi-byte read command*/
  for (i=0; i<8; i++) //Continuous writing must be 8 bytes, otherwise it cannot be written
   {
   *pSecDa = DS1302_Read(); /* Read 1Byte data*/
   pSecDa++;
   }
  DS1302_Close();//Close DS1302
}

void DS1302Write_Time(uchar *pSecDa) //Write clock data to DS1302 (multi-byte mode)
{
  uchar i;
  DS1302Byte_Write(0x8e,0x00); /* Control command, WP=0, write enable*/
  DS1302_Open();//Open DS1302
  DS1302_Write(0xbe); /* 0xbe: clock multi-byte write command*/
  for (i=0; i<8; i++) /*8Byte = 7Byte clock data + 1Byte control*/
   {
    DS1302_Write(*pSecDa);/* Write 1Byte data*/
    pSecDa++;
   } 
  DS1302_Close();//Close DS1302
}

Keywords:c51 Reference address:Defining unions and structures in c51

Previous article:C8051F410 Online Debug Interface Description
Next article:Solution to the problem of not finding c51.exe when compiling and linking C8051F

Recommended ReadingLatest update time:2024-11-16 15:27

Quick tips, teach you how to use Keil C51 software in three minutes
The KEIL C51 standard C compiler provides a C language environment for software development of 8051 microcontrollers. However, many beginners whose interface is in English are confused after reading many tutorials. This site has specially produced a relatively simple tutorial. It can embed assembly language and retain
[Microcontroller]
Quick tips, teach you how to use Keil C51 software in three minutes
What is the definition format of C51 bit variables?
What is the definition format of C51 bit variables? How to define a bit variable of bdata type byte variable? Answer: bit Bit variable name 1 ] sbit bit variable name = bdata type variable name ^ bit number constant
[Microcontroller]
The difference between address latch 74ls373 and 273 and C51 microcontroller
74LS273    is an octal D flip-flop with common clock reset   74LS373    is a three-state in-phase octal D latch The pinouts of 273 and 373 are the same, the only difference is the functions of pins 1 and 11. For 273 (1). Pin 1 is reset CLR, which is valid at low level. When pin 1 is at low level, output pins 2 (
[Microcontroller]
c51: 24C02 multi-byte read and write
//Function function, //Write 2 data and read them out. #include reg51.h #include intrins.h   //Variable declaration #define uchar unsigned char #define uint unsigned int //Convert the value to character uchar digit ="0123456789ABCDEF"; //延时 1ms void delayms() {  uchar i;  for(i=0;i 250;i++);  for(i
[Microcontroller]
c51: 24C02 multi-byte read and write
Keil uVision4 for ARM adds support for C51
The first step is to have the C51 compiler file (that is, the C51 folder in the Keil directory). You can get it by installing Keil uVison4 for C51 (of course, don't forget to uninstall it afterwards), or by copying a copy to a computer that has already installed it. The second step is to install Keil uVision4 for ARM,
[Microcontroller]
The startup process of C program in keil c51
The assembly starts from org 0000h, so how does Keil C51 start the main() function? Keil C51 has a startup program startup.a51, which is always compiled and linked with the C program. Let's see how it is compiled with the main() function; //The main function is as follows; void main(void) {     while (1) This is an un
[Microcontroller]
Three operations of C51 running light
Three operations of C51 running light 1-Project Directory Main function #include reg52.h #include"led.h" #include"delay.h" int main() { liushuianwei(); //bitwise delay_xms(1000); liushuixunhuan(); //Circular shift delay_xms(1000); liushuiyiwei();//Shift delay_xms(1000); while(1); re
[Microcontroller]
Three operations of C51 running light
3*3 matrix keyboard program for C51 microcontroller
#include   #include dis.h /**Delay 1**/ //Used for debounce void delay1(void) {uchar i;  for(i=0;i 200;i++);  } /****Delay 2**********/  void delay2(void) {   uchar i,j,s;   for(i=250;i 0;i--)   for(j=250;j 0;j--)   for(s=5;s 0;s--); } /****Serial port initialization****/ void chuankou_init(void) {
[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号