ARM Basic Knowledge

Publisher:京玩儿Latest update time:2019-10-23 Source: 51heiKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In addition to normal saving, after compiling correctly, choose to save as a .h file with the same name, and change the main function name in the h file to other names, such as xmain, or main1, etc., then the new project can call the function in the original project!

1. Project 1 first write LCD1602, and after compiling without error, save LCD1602.c as LCD1602.h, and change the main() function file in LCD1602.h to main0()

#include

#include

sbit rs=P2^0;

sbit rw=P2^1;

sbit e=P2^2;

void delay(unsigned char us)

{

  while(us--);

}

void w1602(bit r,unsigned char dat)

{

  rs=r;

rw=0;

e=0;

P1=dat;

delay(3);

e=1;

delay(7);

e=0;

}

void init1602()

{

    w1602(0,0x38);

 w1602(0,0x06);

 w1602(0,0x0c);

 w1602(0,0x01);

}

void main()

{

  char i;

init1602();

w1602(0,0x80);

for(i=0;i<10;i++)

 {

        

 w1602(1,0x30+i);

    }

2. Create DS1302 perpetual calendar project DS1302

#include "reg52.h"

#include "intrins.h" //Note that the above project is imported into this project as a header file

#include "LCD1602.h"

sbit rst=P2^3;

sbit sclk=P2^4;

sbit Dio=P2^5;

sbit A7=ACC^7;

sbit B0=B^0;

void w1302(unsigned char addr,dat)

{

  char i;

rst=0;

sclk=0;

rst=1;

for(i=0;i<8;i++)

{

B=addr>>i;     

sclk=0;

Dio=B0;

sclk=1; 

   }

for(i=0;i<8;i++)

{

     B=dat>>i;     

sclk=0;

Dio=B0;

sclk=1;

   }

rst=0;

}

unsigned char r1302 (unsigned char addr)

{

  char i;

rst=0;

sclk=0;

_nop_();

rst=1;

for(i=0;i<8;i++)

{

     B=addr>>i;     

sclk=0;

Dio=B0;

sclk=1;

   } 

for(i=0;i<8;i++)

{     

A7=Dio;

sclk=1;

ACC=ACC>>1;

sclk=0; 

   }

rst=0;

return(ACC);

}

void main()

{

init1602(); //The functions in the above project can be called unconditionally

w1302(0x80,0x33);

while(1)

{

    w1602(0,0x80);

w1602(1,0x30+((r1302(0x81)>>4) & 0x0f));//Call

w1602(1,0x30+(r1302(0x81) & 0x0f));//Call

  }

3. Create a temperature DS18B20 program project

#include "reg52.h"

#include "intrins.h"

#include "LCD1602.h"

sbit ds18b20=P2^6;

unsigned char dd[]="date:";

unsigned char dd1[]="temp:";

unsigned char temp1,temp2,TT,ttT;


bit Reset(void)

{

   bit k;

   ds18b20=0;   

   delay(145);     

   ds18b20=1;      

   delay(10);   

   k=ds18b20; 

   delay(90);

   return k;

}

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

unsigned char ReadByte(void)

{

   unsigned char j,buf=0;

   for(j=0;j<8;j++)

   {

        buf=buf>>1;

        ds18b20=0; 

        _nop_(); 

        _nop_();

        ds18b20=1; 

        _nop_(); 

        _nop_();

        _nop_();

        _nop_();

        _nop_();

        _nop_();

        if(ds18b20==1)

            buf|=0x80;

        delay(8);

                   

     }

   return buf;

}

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

void WriteByte(unsigned char dat)

{

    unsigned char j;

    for(j=0;j<8;j++)

     {             

       if(dat&0x01)

         {      

            ds18b20=0; 

            _nop_();

            _nop_();

            ds18b20=1;

            delay(10);

         }

      else 

         {            

            ds18b20=0;

            delay(10);

            ds18b20=1; 

            _nop_();

            _nop_();

         }

    dat=dat>>1;

 }

}

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

bit Convert(void)

{    

 if(Reset()==0)

     {  

        WriteByte(0xcc);

        WriteByte(0x44);

        return 1; 

     }

 else   

     {   

        return 0; 

     }

}

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

void ReadFlash(void)

{    

 unsigned char Lsb,Msb; 

    if(Reset()==0)

      {

        WriteByte(0xcc);

        WriteByte(0xbe);

        Lsb=ReadByte();

        Msb=ReadByte();

        temp1=Lsb; //L 8bit

        temp2=Msb; //H 8bit

      } 

     else

      {

        temp1=0;

        temp2=0;

      }

}

void disp_temp(unsigned char addr)

{

char i,m;

   

         if(Convert()==1)      

              {      

                ReadFlash();               

                TT=(temp2<<4)|(temp1>>4)&0x7F;

if((TT & 0x80)==0x80)

                     ttT=(~TT & 0x3F)+1;

else

     ttT=TT;

              }

m=20;

while(m--)

{

w1602(0,addr);

for(i=0;i<5;i++)

    w1602(1,dd1[i]);

if((TT & 0x80)==0x80) //-

    {

       if(TT==0x80)

{

   ttT=128;

    w1602(1,0x20);

                                            w1602(1,0X30+(ttT/100));

    w1602(1,0x30+(ttT%100)/10);

     w1602(1,0x30+ttT%10);

                                         }

else

{

    w1602(1,0x20);

    w1602(1,0x2d);

                    if(ttT/10>0)

w1602(1,0x30+ttT/10);

    else

        w1602(1,0x20);

     w1602(1,0x30+ttT%10);

}

}

  else //+

                                           {

w1602(1,0x20);

  if(ttT/100>0)

{

       w1602(1,0X30+(ttT/100));

w1602(1,0x30+(ttT%100)/10);

w1602(1,0x30+(ttT%10));

}

   else

{

if((ttT%100)/10>0)

{

w1602(1,0x30+(ttT%100)/10);

w1602(1,0x30+ttT%10);

}

else    

   w1602(1,0x30+ttT%10); }       

              }

                                              w1602(1,0x22);

w1602(1,0x43);

w1602(1,0x20);

w1602(1,0x20);

}

}

void main()

{

init1602();

while(1)

{

        disp_temp(0xc3);

       }

}

 4. Establish comprehensive project DS1302_18B20

#include "reg52.h"

#include "intrins.h"

#include "DS1302.h"

sbit ds18b20=P2^6;


unsigned char dd[]="date:";

unsigned char dd1[]="temp:";

unsigned char temp1,temp2,TT,ttT;


bit Reset(void)

{

   bit k;

   ds18b20=0;   

   delay(145);     

   ds18b20=1;      

   delay(10);   

   k=ds18b20; 

   delay(90);

   return k;

}

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

unsigned char ReadByte(void)

{

   unsigned char j,buf=0;

   for(j=0;j<8;j++)

   {

        buf=buf>>1;

        ds18b20=0; 

        _nop_(); 

        _nop_();

        ds18b20=1; 

        _nop_(); 

        _nop_();

        _nop_();

        _nop_();

        _nop_();

        _nop_();

        if(ds18b20==1)

            buf|=0x80;

        delay(8);

                   

     }

   return buf;

}

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

void WriteByte(unsigned char dat)

{

    unsigned char j;

    for(j=0;j<8;j++)

     {             

       if(dat&0x01)

         {      

            ds18b20=0; 

            _nop_();

            _nop_();

            ds18b20=1;

            delay(10);

         }

      else 

         {            

            ds18b20=0;

            delay(10);

            ds18b20=1; 

            _nop_();

            _nop_();

         }

    dat=dat>>1;

 }

}

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

bit Convert(void)

{    

 if(Reset()==0)

     {  

        WriteByte(0xcc);

        WriteByte(0x44);

        return 1; 

     }

 else   

     {   

        return 0; 

     }

}

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

void ReadFlash(void)

{    

 unsigned char Lsb,Msb; 

    if(Reset()==0)

      {

        WriteByte(0xcc);

        WriteByte(0xbe);

        Lsb=ReadByte();

        Msb=ReadByte();

        temp1=Lsb; //L 8bit

        temp2=Msb; //H 8bit

      } 

     else

      {

        temp1=0;

        temp2=0;

      }

}

void main()

{

unsigned char i;

init1602();

while(1)

{

           if(Convert()==1)      

              {      

                ReadFlash();               

                TT=(temp2<<4)|(temp1>>4);

                ttT=(~TT & 0x3F)+1;

              } 

     //week

w1602(0,0x81);

for(i=0;i<5;i++)

w1602(1,dd[i]);

        w1602(1,0x30+((r1302(0x85)>>4) & 0x0f));

             w1602(1,0x30+(r1302(0x85) & 0x0f));

w1602(1,0x2d);

w1602(1,0x30+((r1302(0x83)>>4) & 0x0f));

             w1602(1,0x30+(r1302(0x83) & 0x0f));

w1602(1,0x2d);

w1602(1,0x30+((r1302(0x81)>>4) & 0x0f));

             w1602(1,0x30+(r1302(0x81) & 0x0f));

  w1602(0,0xc3); //temp

for(i=0;i<5;i++)

w1602(1,dd1[i]);

 if(temp2 & 0x80==0x80) //-

   {

      w1602(1,0x2d);

w1602(1,0x30+ttT/10);

      w1602(1,0x30+ttT%10);

}

 else //+

              {

w1602(1,0x20);

w1602(1,0x30+TT/10);

w1602(1,0x30+TT%10);

              }

            w1602(0x22,1);

w1602(0x43,1);

  }

}


Keywords:ARM Reference address:ARM Basic Knowledge

Previous article:Linux Embedded ARM-Linux Basics
Next article:Let ADS and KEIL coexist Warning: L6373W: libattrs.map file not found

Recommended ReadingLatest update time:2024-11-23 07:33

Configure arm linux Qt development environment
The process of configuring the arm linux Qt development environment is relatively complicated, so it is necessary to record the steps. Version: Ubuntu10.04 LTS / Qt SDK 4.7.3 / arm-linux-gcc 4.4.3   1. Install arm-linux-gcc compiler 1. Download arm-linux-gcc-4.4.3, http://ishare.iask.sina.com.cn/f/13836544.html 2. Af
[Microcontroller]
【ARM bare board】Software interrupt analysis and examples
1. How to switch modes in APP APP generally runs in User Mode and is subject to restrictions (for example, it cannot access hardware) If the APP wants to access the hardware, it must switch modes How to switch? When an exception occurs: Soft interrupt, swi #val Interrupt Undefined instruction exception 2. Soft process
[Microcontroller]
【ARM bare board】Software interrupt analysis and examples
ARM7 learning --- key test program (LPC2103 IO0PIN)
Today I have been learning the key test program. It looks very simple. Everyone can use keys. They have been used in many types of microcontrollers. However, I still encountered a problem today, and it took me half a day to debug and find the problem. At first, I didn't know how to use the GPIO of LPC2103. Later, I che
[Microcontroller]
Design of intelligent vehicle terminal equipment system based on ARM
 1 Overall construction of the system   The intelligent vehicle management system consists of three parts: intelligent vehicle terminal equipment, GPRS wireless communication link and master station monitoring center. The overall structure diagram is shown in Figure 1. Figure 1 Block diagram of the intellige
[Microcontroller]
Design of intelligent vehicle terminal equipment system based on ARM
The ubiquitous Arm software and hardware ecosystem empowers developers to innovate in AI
Author: Geraint North, Vice President of Developer Platform, Strategy and Ecosystem, Arm Artificial intelligence (AI) is one of the most significant technological changes today, and is driving the development of all industries at an unprecedented pace. As the most widely used computing architecture,
[Embedded]
Analysis of Parallelization Methods for Embedded ARM Multi-core Processors
     At present, embedded multi-core processors have been widely used in the field of embedded devices, but embedded system software development technology is still stuck in the traditional single-core mode, and has not fully utilized the performance of multi-core processors. Program parallel optimization is currently
[Microcontroller]
Analysis of Parallelization Methods for Embedded ARM Multi-core Processors
ARM development board learning experience
I have been learning ARM for a while now, so I think I should remember something, or I will forget it later. This is my first piece.    Simple, but basic.    1. Explanation of some common English abbreviations in ARM    MSB: most significant bit;    LSB: least significant bit;    AHB: Advanced High-P
[Microcontroller]
ARM40-A5 application - adaptation of fbset and LCD screen parameters
To use a certain type of LCD on an ARM board, you often have to modify the LCD driver or device tree, which is very inconvenient. In ARM40-A5, we store the configuration instructions of commonly used LCD models in the /etc/init.d/S01user1lcd file. By modifying this file, we can easily adapt to different LCDs.
[Microcontroller]
ARM40-A5 application - adaptation of fbset and LCD screen parameters
Latest Microcontroller Articles
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号