C51函數(shù)基礎編程
1.編寫一C51函數(shù),把從鍵盤輸入的5位十進制數(shù)數(shù)轉(zhuǎn)換成一個無符號整型數(shù)(假設未超出整型數(shù)范圍)。設從鍵盤輸入的數(shù)存放在一無符號數(shù)組中,低位數(shù)為低下標元素。
unsigned char data key_buffer[5];unsigned int trans_int(void){ unsigned char data i; unsigned int data temp=0; for(i=0;i<5;i++) { temp=temp*10+key_buffer[i]-0x30; } return temp;} 2.編寫一C51函數(shù),把一整型數(shù)按十進制數(shù)將其各位分離,分離后放在一無符號數(shù)組中,便于顯示。要求把低位數(shù)作為低下標元素。unsigned char data shu[5];void main(unsigned int x){unsigned int temp;unsigned char i;for(i=0;i<4;i++){ shu[i]=temp%10; temp=temp/10;}shu[4]=temp;} 3.編寫一C51函數(shù),使用專用指針,把片外數(shù)據(jù)存儲器中從0x100開始的30個字節(jié)數(shù)據(jù),傳送到片內(nèi)從0x40開始的區(qū)域中。void main(){ unsigned char data i,*dpt; unsigned char xdata *xdpt; dpt=0x40; xdpt=0x100; for(i=0;i<30;i++) *(dpt+i)=*(xdpt+i);} 4.編寫一C51程序,實現(xiàn)從P1口輸出產(chǎn)生的流水燈,要求用匯編語言函數(shù)實現(xiàn)數(shù)據(jù)左移或右移。#pragma src#include <at89x52.h>void main(){ unsigned char temp,i; while(1) {temp=0x55;P1=temp;delay();#pragma asmMOV A,tempRR AMOV temp,A#pragma endasmP1=temp;delay();}}編輯:admin 最后修改時間:2018-05-19