avr learning 2 AVR assembler

Publisher:EtherealGraceLatest update time:2016-10-21 Source: eefocusKeywords:avr Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
When I first started learning about each CPU, I would first study the corresponding assembly instructions. I felt that this would allow me to quickly experience the hardware principles of the CPU, which would be very helpful for subsequent learning. Many people think otherwise, and feel that assembly is cumbersome and difficult to use. In fact, this will not give you a deep understanding of the internals of the microcontroller. Some basic assembly is very useful in single-step debugging, as well as scheduling writing, operating system porting, etc.

The following is an assembly program for making an LED flash. The comments are written in C, which is very clear.
**********************************************************************
//CPU: mega32
//Compiler: iar

        #include
        NAME main
        
        PUBLIC main
        
        ORG RESET_vect ; Reset interrupt vector
        RJMP main
        
        ORG INT0_vect ; External interrupt 0 interrupt vector
        rjmp eint0
        
main   

        ldi r16,0x99
        out DDRD,r16
        lds r1,DDRD
        cli
        ldi r16,high(RAMEND) ;get the high byte of the highest address of internal RAM
        out SPH,r16 ;put into the high position of SP
        ldi r16,low(RAMEND) ;get the low byte of the lowest address of internal RAM
        out SPL,r16 ;put into the low position of SP
       

        ;DDRD |= (1 << 7);//PD7 is set as outputin
        r16,DDRD
        sbr r16,1<<7
        out DDRD,r16
        
        
        ;eint0_init();
        call eint0_init
        
        ;sei();
        sei
        
        ;while(1);
        s: rjmp s
        
        
        ;#pragma vector = INT0_vect
        ;__interrupt void eint0(void) //INT0 interrupt service
        routineeint0:
        ;PORTD ^= 1<<7;//PD7 is invertedin
        r16,PORTD
        sbrs r16,7
        ldi r17,1<<7
        eor r16,r17
        out PORTD,r16
        
        reti
        
        
        ;void eint0_init(void)
        eint0_init:
        ;DDRD &= ~(1 << 2);//INT0 pin inputin
        r16,DDRD
        cbr r16,1<<2
        out DDRD,r16
        ;PORTD |= (1 << 2);//INT0 internal pull-up resistor is validin
        r16,PORTD
        sbr r16,1<<2
        out PORTD,r16
        ;SFIOR &= ~(1<         r16,SFIOR
        cbr r16,1<         out SFIOR,r16
        ;MCUCR |= (1 << ISC01) | (1 << ISC00);//INT0 falling edge triggerin
        r16,MCUCR
        sbr r16,(1 << ISC01) | (1 << ISC00)
        out MCUCR,r16
        ;GICR |= (1 << INT0);//Enable INT0
        in r16,GICR
        sbr r16,1 << INT0
        out GICR,r16
        
        ret


        END main
************************************************ *********************

Keywords:avr Reference address:avr learning 2 AVR assembler

Previous article:AVR MCU Getting Started Series (17) AVR IO Input Matrix Key Scanning Program
Next article:AVR MCU and GCC Programming Methods

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

Special IC decryption technology AVR application skills
Compared with traditional single-chip microcomputers, AVR has made great improvements in terms of structure, functional components, performance and reliability in addition to being able to realize some basic functions in IC chip decryption technology. However, using better devices only creates a good foundation
[Microcontroller]
An experience of AVR fuse burning and recovery - detailed analysis and solution
Environment Target device: MEGA64L Burning software: PonyProg2000 (Version 2.06c Beta Jul 27 2003) Burning hardware: According to http://www.LancOS.com, use 224 self-made burning line Burning process I made several new DEMO boards. After soldering, the first one burned OK. When burning the second one, I used the wron
[Microcontroller]
ADC application of avr microcontroller
1. Basic knowledge of digital-to-analog conversion         The digital-to-analog converter (ADC) is basically a matter of ratio, that is, the digital value generated by the ADC is related to the ratio of the input analog value to the converter range. The conversion relationship is as follows:            Vin/Vfullsca
[Microcontroller]
AVR microcontroller tutorial - serial port receiving
In the previous lecture, we realized the data transmission from the MCU development board to the computer. In this lecture, we will send instructions to the MCU through the computer, so that the MCU can control the LED according to the instructions. This time, the TX and RX at both ends need to be cross-connected, and
[Microcontroller]
Design of reactive power compensation controller based on ATT7022A and AVR microcontroller
    A reactive power compensation controller is designed with the three-phase power metering chip ATT7022A and a high-performance, low-power AVR microcontroller atmega128 as the core. The controller can measure the current and voltage values, active power, reactive power, power factor and other parameters of the power
[Microcontroller]
Design of reactive power compensation controller based on ATT7022A and AVR microcontroller
Left shift and right shift instructions in AVR microcontroller
The computer's instruction system is a set of codes that control the operation of the computer, called machine language. Computers can only recognize and execute machine language instructions. In order to make it easier for people to understand, remember and use, assembly language instructions are usually used to desc
[Microcontroller]
Left shift and right shift instructions in AVR microcontroller
CAN bus application based on AVR processor at90can128
1 Introduction Fieldbus is the most active field in the current industrial bus field, and CAN bus is one of the important fieldbuses in the industrial data bus field. CAN is the abbreviation of Control Area Network, which is an internationally standardized serial communication protocol. In today's automotive in
[Microcontroller]
CAN bus application based on AVR processor at90can128
Design of fully automatic solar energy water heater controller based on AVR single chip microcomputer
introduction With the improvement of people's living standards, the use of various water heaters has become quite popular, and the corresponding controllers have also come out one after another. However, the various water heater control circuits on the market are still far from the ideal requirements. Consumers need r
[Microcontroller]
Design of fully automatic solar energy water heater controller based on AVR single chip microcomputer
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号