|
这是我自己编的程序 不晓得对不对 请大家帮我看哈 有么问题
4 F9 ~6 R2 Y8 H# P5 }3 ?! y- W: O程序代码:$ i: Q- s+ @7 [ S
//ICC-AVR application builder : 2009-07-20 9:29:54
, q$ M* I s4 d3 E// Target : M16
, J- R" l8 y6 {// Crystal: 8.0000Mhz
! m) ]$ L D2 d5 J" B$ L#include <iom16v.h>
6 a" ]7 V7 T {( _3 ^#include <macros.h>! F: b+ I& R6 c8 u; c# L( }) @) d7 } I3 J
//#include <delay.h>
# g# V8 N3 R4 R. s4 c# ^0 G#define uint unsigned int
# t4 g; G- e5 p; e l0 X#define uchar unsigned char
6 ~8 Q& C3 I5 [ @1 b' Tunsigned char Table[11]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x79};- ^; G3 o1 V: X/ K2 A
unsigned char Data[4]={0,};int getdata;# @) i" u. K8 i) s" Q; X
int a;
' Y) b6 q: a% O* p4 f0 ]( Xvoid DelayMs (unsigned int i)//延时函数 6 C/ ~) `7 y3 ?
{
7 j% x0 n: }: n: B8 D unsigned int j;
/ y1 N" L. k5 N$ f for (;i!=0;i--)! E; Z% o* j8 \* W( d% j$ T% d
for (j=50;j!=0;j--);
/ w) v3 }* J0 }" r( @: c}4 }3 d+ E9 I+ B( s
void delay_us() //延时子程序
- B; N4 H4 g# W C J' w{1 K$ u" L/ ] D: P7 s
; S1 U) f: J3 _
//while(--t);9 D) \, T1 X8 g% n5 q
}+ O/ `0 Z+ v1 a
void dly(unsigned int t)
5 d; h" N" q% e0 Y9 G0 l# l{
3 b( q$ L) p6 {4 W" y ;
3 ?+ k1 a9 f; D/ a" D, Y2 e}' \1 X2 P) N8 {
void port_init(void)
' C! O" L' ~- Y# K0 M' y8 }7 a{1 K( G' q/ z% a$ p( C, E# I
PORTA = 0xFF;* T5 l! m. o* Y- d/ o3 R: v
DDRA = 0x00;) |* ~5 v7 @ ?
PORTB = 0xFb;9 x( I I6 M) ], h9 I: [
DDRB = 0xFB;9 q1 _- b: a! g7 [6 Y' e
PORTC = 0xfF;2 W; C( c2 v5 N s' [
DDRC = 0xfF;6 e- }/ f# @3 |$ C
PORTD = 0xFF;
" v, W6 J: a, ?5 D DDRD = 0xFF;
! w W% q0 L4 O* @7 U}
6 H# d$ _% v1 D6 D5 H8 R# g6 n7 g5 Tvoid Display(unsigned char *p)' L/ K9 J+ a" l- Q, [- D
{& t( o0 _8 M6 x, F2 I
unsigned sel=0x01,i; 7 L* B. W* I3 B( w9 \
for(i=0;i<4;i++)" q' ^- X. g& W/ |) n. ]& P$ j: `
{ / Z! m! @! s5 R5 t. b- V
PORTC=~sel;
: S; u/ U, Z, ^" Z: Y PORTD=Table[p[3-i]];
2 [* x1 L* G- G+ f+ ] DelayMs(1);5 T+ x6 T4 }+ ^2 n4 |
sel=sel<<1;6 g1 t; t$ c; x/ i
}
7 b5 e$ v( s% H}
1 A' c/ m F! dvoid xiangshi( int x)//led显示子程序/ T2 W+ h1 L+ e/ [' M
{% @$ c& y! D( q, L: U+ V0 g
Data[3]=x/1000;
( i( ?5 w5 H x4 b Data[2]=x%1000/100;1 @$ G: L* d) m: ]
Data[1]=x%100/10; , K7 v- l: ]* l6 Y5 k( ]$ c
Data[0]=x%10;
+ b6 [" C5 Y; ^" C. R/ B }
% X4 s k2 R, x: f#pragma interrupt_handler jishi:10( o7 l: L# p" q9 T% q. Z0 \: o
void jishi()
, \' B0 e- J4 W( T" C; l{
Y7 @7 V% ~: ` a++;2 g Q" s! S b: [2 S- F/ Z
a%=100000;
7 K" ~ O9 a+ F9 b- J}
% m; Q) o/ Y7 h0 t3 `$ H& Avoid time()
7 b' f, s) c X/ S+ p# r! G{
8 |& v9 `; h# {# p* K* D( f& q5 { TCCR1B=0X01;
4 b. z- F* O4 w# {. B TCNT1H=0X7f;
6 H( l! J$ ]2 x4 a$ E( ?% t TCNT1L=0X9f;) P! l5 O& C4 J5 P1 r; P
TIMSK|=BIT(2);- [: h* |7 Z* t/ y+ w) E) ~8 g
SREG|=BIT(7);! E0 z6 _# j* M$ x: g1 u
}
% t( |5 B4 O* [5 L% Mvoid time0()
5 g- [7 }* U( P/ |{ H" [( E5 m [9 ?1 O8 j3 g! j3 _
TCCR0=0X04;, l4 P' N8 _2 Y/ u% v/ w+ N
//OCR0=0XFF;7 h# v, X ]! n F }3 X; B
TCNT0=0X00;, c/ {2 C5 o; n0 _* U
TIMSK=BIT(1);' V y8 ^+ F1 a( I4 L
SREG|=BIT(7);
9 M. a: G8 ?* ]: ~}
. i; B' o5 I- G0 A; h( v% Dvoid main()5 s* z6 w& D! I- `/ p
{ $ i$ ] a' z4 |5 s% B5 }9 ~
port_init();3 Z9 W6 h4 x; x1 L; m; n
time0();
( ^* { v! M( X; ? U //time();
4 A4 L/ q4 f3 R while(1)
9 Z+ `# C& x& G5 M1 t { $ P6 D( L( y4 Q: _
//PORTB&=0XFE;
$ q6 B5 C: F0 H; k& w. T //delay_us(); 8 u# {$ {' N2 _: ^
//PORTB|=0X01;
% K$ H+ ]% F, c" L9 s/ v/ F0 X // getdata=PINA; 9 g, W" W2 J1 ~3 T! H9 @
// }//从P2口读取数据//
. k! N6 ]# k" {9 p9 {6 s- s( h5 Q% {, W // PORTB&=~BIT(1);//RD=1 使ADC输出数据
6 I0 b7 H% [/ c$ _- x xiangshi(a);
! f+ c+ g- a0 T& u5 ^! S# Y! R% ? Display(Data); //显示// 3 X2 Y* c. W- }
}
* G9 R. g" }. Q# n8 V, S5 I}
& f' ]: I! {" eADC0820.rar' C" K, L) a9 K0 m; z, R
tlC0820.part1.rar. i, k) S( r! u$ p
tlC0820.part2.rar |
|