|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
3D计步器的设计论文下载; X, B: M. V. d0 Q6 ?
o+ c/ U8 ~( x' Y' ^8 ]6 U% `- B% F9 ^) S
3D计步器部分程序:
, W8 S* A' P! E% s& I, C0 t6 U& D2 H& z l' b* |
4 T9 b( W7 f) x8 e; Z& C/ {#include "reg51.h"
" y/ e* N1 R8 _9 B* N#include "intrins.h" + t9 S6 D7 R- r/ I3 s$ w
#include <math.h> : ?7 X) w2 {6 b) A% ~" M2 i
#include <stdio.h>
& s) p/ f) w- z2 f3 X7 ~#define FOSC 18432000L
0 w7 f9 R; k A, G) u0 {#define FOSC 11059200L //晶振 11.0592M
$ c, H0 y% [* {# L S0 I4 P6 y#define BAUD 9600 typedef unsigned char BYTE; typedef unsigned int WORD; ) K0 h. x( f' X) U4 u- N
#define uchar unsigned char uint unsigned int
$ R" Y5 c9 q( d: ]( K: f* C; U4 V+ M( G5 D S
/*Declare SFR associated with the ADC */+ O. @8 c4 ^% U, d
sfr AUXR1 = 0XA2; sfr ADC_CONTR = 0xBC; //ADC control register sfr ADC_RES = 0xBD; //ADC high 8-bit result register sfr ADC_RESL = 0xBE; 2 s- I/ _ t S4 I& X7 ]$ a6 ^
sfr ADC_LOW2 = 0xBE; //ADC low 2-bit result register
; D4 B9 a# E, l% Z8 h3 t, Dsfr P1ASF = 0x9D; //P1 secondary function control register /*Define ADC operation const for ADC_CONTR*/ / G4 I. }/ Y) I- @: v2 E* p i
#define ADC_POWER 0x80 //ADC power control bit
! X) O8 y' p3 o#define ADC_FLAG 0x10 //ADC complete flag : e" V. r L2 d3 \9 _' Y
#define ADC_START 0x08 //ADC start control bit
7 p4 X- {# i( m: K, L9 [' [/ T: w& ~#define ADC_SPEEDLL 0x00 //420 clocks
4 y2 J3 ?6 h' q0 {7 U$ T7 a; z#define ADC_SPEEDL 0x20 //280 clocks
# K" ?2 E5 Y' [4 G3 l! ^% {7 P#define ADC_SPEEDH 0x40 //140 clocks #define ADC_SPEEDHH 0x60 //70 clocks void InitUart(); / r+ L4 j, K) G' V; |5 c% N2 y
void InitADC(); & J- f5 u, _) g# c5 ^2 ?# \
void SendData(BYTE dat);
9 F2 s8 p" \( Hint GetADCResult(BYTE ch);# `6 Z, c" w- z' O1 B
void Delay(WORD n);
( [" m1 W+ g, D3 V0 zuchar ge,shi,bai,qian,wan;
! b. P9 l* Q6 v7 w; T' R2 pVoidconversion(uint temp_data) { wan=temp_data/10000+0x30 ; temp_data=temp_data%10000; qian=temp_data/1000+0x30 ; temp_data=temp_data%1000; bai=temp_data/100+0x30 ; temp_data=temp_data%100; shi=temp_data/10+0x30 ; temp_data=temp_data%10; ge=temp_data+0x30; }3 ?) C1 a" H+ {0 u& }# J
" t1 Z+ o( V8 G' Q2 H- o
//显示变量/ T/ D! D6 ^; `. f# [
& @5 Y$ V8 A5 y5 x4 k3 _
//取余运算 //取余运算 //取余运算 //取余运算 b6 V+ Q6 [8 U) J+ m t
. w, m- l$ h, r9 r, W$ r/*---------------------------Get ADC result ----------------------------*/
* v; h) e* k, r+ }+ \. t7 M9 \int GetADCResult(BYTE ch) { int AD10bitResult; ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ch | ADC_START; _nop_(); //Must wait before inquiry _nop_(); _nop_(); _nop_();2 ^. l1 F% ]# ~# X5 O
while (!(ADC_CONTR & ADC_FLAG));//Wait complete
9 ~: ^% \9 ]4 R; J+ S% jflag ADC_CONTR &= ~ADC_FLAG; //Close ADC AD10bitResult=ADC_RES; 6 V) J- c$ Q: `' `, P
AD10bitResult<<=8; AD10bitResult|=ADC_RESL; return AD10bitResult;
" l F0 ^5 i* p
' G; K) ~8 }1 r6 g6 y//Return 10BIT ADC result1 z: g% ?4 N2 I) e
0 d& T2 k$ a5 p. \/ d: c2 H* n} /*---------------------------Initial UART ----------------------------*/ void InitUart() { SCON = 0x5a; //8 bit data ,no parity bit TMOD = 0x20; //T1 as 8-bit auto reload TH1 = TL1 = -(FOSC/12/32/BAUD); //Set Uart baudrate TR1 = 1; //T1 start running }
g$ r7 r8 Z5 X v% W4 ]
. S! g% U% I9 P+ }) `0 M0 K8 [. J8 F( ~- N7 B/ S% s; D
/*---------------------------Initial ADC sfr ----------------------------*/ void InitADC() { P1ASF = 0xff;" }, _* G, z8 h c
: ^: R% H' ?+ H& S//Open 8 channels ADC function
* {# o3 S& m$ Z; R1 u% a! r- N" }2 `! P7 K7 q5 b. @' H$ r
AUXR1=AUXR1|0X04; //ad 值左对齐 ! ]1 [! j8 ~. O8 X8 W3 X
ADC_RES = 0; //Clear previous result
3 d; Y$ V |7 k: V7 pADC_CONTR = ADC_POWER | ADC_SPEEDLL; Delay(2); //ADC power-on and delay } /*---------------------------Send one byte data to PC Input: dat (UART data) Output:----------------------------*/
n7 Q' ^0 a/ c2 S3 hvoid SendData(BYTE dat) { while (!TI); TI = 0; SBUF = dat; } /*---------------------------Software delay function ----------------------------*/ 2 r, W' [# y2 p, I9 H- v: l
void Delay(WORD n) { WORD x; while (n--) { x = 5000; while (x--); } } //***************************************************************************** * void main()! O: a L; M1 x7 }7 N }: p* U4 ~
' h m/ X' C" A
//Wait for the previous data is sent //Clear TI flag //Send current data- {% V+ E ?* O( m
& b6 j4 p0 P5 S& J2 i+ V- A{6 Z" R/ a6 Y/ }! ^
/ L) V/ }: ^8 J
…………限于本文篇幅 余下代码请从论坛下载附件…………
1 a: I' ?9 p6 c4 k1 G
' e6 k. v3 o4 j @$ U, ]" e9 P. F$ |. J4 ]
5 ?* u& |5 N( d |
|