|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
3D计步器的设计论文下载
; @* x. C5 u+ m& B9 j% @+ I
. _2 M, U, _( V8 |+ v8 U) n( @3 R$ s) W0 ?/ _' c: h/ X7 `/ c" @
3D计步器部分程序:
1 |6 `& C: b4 K$ J0 v
2 O7 W8 {- R1 w% t$ _4 E5 `/ o9 }6 F9 A1 s6 y
#include "reg51.h"
. V. w2 @8 q1 E' A# G#include "intrins.h"
0 t6 t' L" r6 @8 I! K#include <math.h>
5 V7 p" j. m B+ S' U#include <stdio.h> 0 v: a8 o* r; q2 K3 Z2 O* y' W
#define FOSC 18432000L
- X$ A' [' R2 \* y; a$ f# q7 z% O#define FOSC 11059200L //晶振 11.0592M
+ t* G5 E4 k7 i: v#define BAUD 9600 typedef unsigned char BYTE; typedef unsigned int WORD;
& _' D; D8 F2 I#define uchar unsigned char uint unsigned int, J+ p, a0 ?& J8 o3 E. V2 d. Q
* F9 m Y0 m( t& M; o0 @* b/*Declare SFR associated with the ADC */( n7 n) ?, M$ k6 I! J
sfr AUXR1 = 0XA2; sfr ADC_CONTR = 0xBC; //ADC control register sfr ADC_RES = 0xBD; //ADC high 8-bit result register sfr ADC_RESL = 0xBE; + h' g) T, Y* h C" D* Y
sfr ADC_LOW2 = 0xBE; //ADC low 2-bit result register 7 \1 c! n8 i9 K, e
sfr P1ASF = 0x9D; //P1 secondary function control register /*Define ADC operation const for ADC_CONTR*/ * K+ Y7 w4 P" P
#define ADC_POWER 0x80 //ADC power control bit 3 n, E+ E* W, N/ W2 g
#define ADC_FLAG 0x10 //ADC complete flag 4 c! r, {/ }+ A- h5 W5 t0 e4 m
#define ADC_START 0x08 //ADC start control bit
5 ^) {; Q& s; P5 c$ {#define ADC_SPEEDLL 0x00 //420 clocks 5 }" _0 e" E* W# L' \6 ]% I/ l- \
#define ADC_SPEEDL 0x20 //280 clocks ' A) P3 ~; P2 R; H# L% _& q
#define ADC_SPEEDH 0x40 //140 clocks #define ADC_SPEEDHH 0x60 //70 clocks void InitUart();
( Y# s0 Z9 `- A7 n2 q) U' o2 i; yvoid InitADC(); % s# j3 {5 K# _. P% [9 ^4 u- J5 u0 O
void SendData(BYTE dat);
( S3 B% ` q( f9 p4 uint GetADCResult(BYTE ch);
6 p$ C) I+ p6 t6 Y: a; Y2 n7 w/ X' pvoid Delay(WORD n); . j! ^2 ^0 C8 ^& ^0 a f5 W
uchar ge,shi,bai,qian,wan; & r! r5 u8 g. X0 ?$ h
Voidconversion(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; }
% X, d( v! i0 a# R6 B0 K3 e1 W* H" Q' Z3 o% {) x, |" s8 F. Z
//显示变量# `8 f! D+ M1 q9 ?; Y. R# B# e/ R
$ b! v) P P+ i( X6 m8 w//取余运算 //取余运算 //取余运算 //取余运算
4 \ k# M6 F) e+ v8 X
A5 E% ]3 }% i( ?) |/*---------------------------Get ADC result ----------------------------*/ B& L: `: G+ I" E0 r1 F7 z
int GetADCResult(BYTE ch) { int AD10bitResult; ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ch | ADC_START; _nop_(); //Must wait before inquiry _nop_(); _nop_(); _nop_();% P q! O( k$ f8 {# [, V% b/ G
while (!(ADC_CONTR & ADC_FLAG));//Wait complete
# S$ _, L( e3 W8 w F& }7 Uflag ADC_CONTR &= ~ADC_FLAG; //Close ADC AD10bitResult=ADC_RES; - i/ c# Z8 A& Q S- b/ q
AD10bitResult<<=8; AD10bitResult|=ADC_RESL; return AD10bitResult;5 ^! E, K9 D P! l# s9 O
0 S w/ f6 e& d7 q, d//Return 10BIT ADC result6 q) M0 L+ y! b4 X8 ~; L1 e! m
) j6 s3 o8 S! s3 H} /*---------------------------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 }& b7 L9 o' {3 m# F+ v
. ?- c4 N6 t9 a7 I
' c& d' @& X- B! U5 g6 B
/*---------------------------Initial ADC sfr ----------------------------*/ void InitADC() { P1ASF = 0xff;
, |" G: |7 R$ ]( k1 \! l' `
- Q% \. y: ~8 _/ I7 b, r) W//Open 8 channels ADC function
' d* K) \& B; u3 ]/ J0 y' \! P$ c. i2 P
AUXR1=AUXR1|0X04; //ad 值左对齐 . _ v. e) u; C: T/ F2 d
ADC_RES = 0; //Clear previous result 8 T3 Z1 H- x( X% o! I9 I U; f
ADC_CONTR = ADC_POWER | ADC_SPEEDLL; Delay(2); //ADC power-on and delay } /*---------------------------Send one byte data to PC Input: dat (UART data) Output:----------------------------*/
2 j# C0 n5 h- c* |/ P1 rvoid SendData(BYTE dat) { while (!TI); TI = 0; SBUF = dat; } /*---------------------------Software delay function ----------------------------*/
2 f/ t' o% x* p! Z7 T0 E/ v0 o4 xvoid Delay(WORD n) { WORD x; while (n--) { x = 5000; while (x--); } } //***************************************************************************** * void main(); B( n* a K8 R4 A. [
, @- L+ q; z p//Wait for the previous data is sent //Clear TI flag //Send current data
. U8 n# y& ?9 b3 k4 ^) ?
# Z# a- d# H1 n& o{" j, ~' k; A. B, j" X! s
3 r k7 [4 J- N" b- ^
…………限于本文篇幅 余下代码请从论坛下载附件…………
( X3 O# G& k2 n2 p- e/ e& P, h x
q ~4 B5 t/ U; K( I" l! i
, c5 r1 s* g3 G( J# E
4 n+ B0 A, d9 g* e |
|