Mixed programming of A51 and C language

Publisher:BlissfulSpiritLatest update time:2012-08-10 Source: 51heiKeywords:A51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I spent a whole morning studying and wrote a program. It is small but complete. I hope that people who are learning this can spend less time searching for information and master it faster.

#include 
/****Define in assembly*****/
extern void delay(void) ;
extern add(int a,int b);
//Test assembly call code (do not want to use assembly directly to run the main program)
extern void test();
/***Code segment defined in assembly****/
extern unsigned char cc;

// Function defined in C language
void delay_c();
unsigned int addcc(unsigned int wd1,unsigned int wd2);
//Data segment defined in C language
unsigned int aa;
unsigned int bb;

void main()
{
  
   delay();
   cc=add(10,15);
   test();
   while(1);
}
void delay_c()
{
  unsigned char cc;
  cc=0xff;
  while(cc--);
}
unsigned int addcc(unsigned int wd1,unsigned int wd2)
{
unsigned int cl;
cl=wd1+wd2;
return cl;
}


delay.asm


NAME ONE ; name of the module
;ORG 1000H ;Starting unit where the function is stored
?PR?delay?ONE SEGMENT CODE ; mark the definition location of the function
?PR?_add?ONE SEGMENT CODE
?PR?test?ONE SEGMENT CODE
cc DATA 33H ;Directly define the data address
PUBLIC delay ; declared as global
PUBLIC _add
PUBLIC test
PUBLIC cc ; declare global
EXTRN DATA(aa); Note that this is extrn instead of extern in C. Defined in C
EXTRN DATA(bb)
EXTRN CODE(delay_c)
EXTRN CODE(_addcc); I did not test the online information with parameters EXTRN CODE(addcc) successfully.
Logically, the name should be added with _fun, which is a definition method with parameters.
;EXTRN DATA(?_addcc?BYTE) ;I have not been able to successfully pass this method to upload parameters online, so I directly processed the data on the register.

   RSEG ?PR?delay?ONE ; (without parameter function) relocate the code position of the function
delay:
   MOV R0 , #44H
   DJNZ R0,$
   RET
  RSEG ?PR?_add?ONE ; (function with parameters) The parameters are automatically prevented from being put into the register. You can check it online.
Here 15 is stored in R7, R6 and 10 is stored in R5, R4
_add:
   MOV A,R5
   ADD A,R7
   MOV R7,A
   MOV A,R4
   ADDC A,R6
   MOV aa,R7
   RET

RSEG PR test ONE
test:
  ; Use C function without parameters
  CALL delay_c
  ;Call a C function with parameters
  MOV R5,#15
  MOV R7,#11
  LCALL _addcc
  MOV cc,R7
  RET
  END ; End of program
Keywords:A51 Reference address:Mixed programming of A51 and C language

Previous article:74HC595 drives 24-bit digital tube
Next article:STC12C5A60S2 MCU PWM Program

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号