|
这是我自己编的程序 不晓得对不对 请大家帮我看哈 有么问题: ~# i8 I; ^: o h/ M7 v/ n
程序代码:
. z9 z @. r" V//ICC-AVR application builder : 2009-07-20 9:29:54
. D( p8 Q1 l( t% v3 q/ {, X// Target : M16+ P; B& c8 d2 _: o' z; `! {, d
// Crystal: 8.0000Mhz
1 c' ?( F. ^$ Q8 H( O% z. F6 S#include <iom16v.h>; V6 N+ G* a" ?8 x6 D( P$ ]
#include <macros.h>
% H/ W1 E: h4 D- _ s//#include <delay.h>
9 n: K8 B- ~) f; z$ N0 f#define uint unsigned int
) U |+ w1 s; R; J) v#define uchar unsigned char
8 f8 Q$ K0 ^" N% K% W( O munsigned char Table[11]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x79};
2 Q! {$ x; @" [0 x2 \- sunsigned char Data[4]={0,};int getdata;% D( z$ s+ z4 q9 }/ `, u
int a;
4 V- e, m2 S6 ?, O. avoid DelayMs (unsigned int i)//延时函数
( \4 T3 a, d. y{ 3 s, C5 i% Y# c8 s# O* O$ {
unsigned int j;/ W4 F4 j. i/ S y! @
for (;i!=0;i--)6 k& J* ^# M! ~9 |
for (j=50;j!=0;j--);
" _; W" b. k9 e6 Z# q}
9 x! M9 `1 c' H! s0 Kvoid delay_us() //延时子程序
2 V3 N( X6 @& D+ f8 ^+ q8 u{; k" L8 O$ ?& J, [0 q1 v3 M
;) u. I7 t* i' m% F9 i
//while(--t);, ^3 D4 m5 R4 `& s3 Y( j/ a, ]5 d
}# V" c- C; c2 S5 Y
void dly(unsigned int t)' b) x) H+ t+ [5 U9 j/ L# }
{
2 z: ?7 d" c1 w, ?0 H- g3 a ;
. |& L! O5 `8 r6 c+ C}5 z9 y3 O1 D; d( [. X
void port_init(void); r, G; X4 K0 i' k
{
) {+ I& R5 I* Z PORTA = 0xFF;
5 a' @1 ?6 |6 M! h f DDRA = 0x00;0 Q7 F( I1 ?5 d+ y- I
PORTB = 0xFb;
: t1 K% D( x3 e* @ DDRB = 0xFB;
3 w( z0 l! Q- |7 v+ W# ^: `( J* u" D PORTC = 0xfF;
9 [. ^; \$ V- u" ~ DDRC = 0xfF;
5 @; H L2 m' m( }4 S Y4 u PORTD = 0xFF;
4 J ]) X5 x2 J. F DDRD = 0xFF;
8 J2 h' ^( i8 X1 E$ ?}' s+ B8 `$ ^, G7 l' W1 ?
void Display(unsigned char *p)
' k+ m3 ]* i. J1 A( y+ s& i{! A, q7 a' E1 l2 }( q1 v0 M3 d0 U
unsigned sel=0x01,i; Y# f- p0 u) C: w d, }
for(i=0;i<4;i++)
, B! X' t0 s& g) y {
; I6 t# k7 n2 ^ c PORTC=~sel;
0 `. g9 K* S# K! p. v7 G PORTD=Table[p[3-i]];2 R! o# o8 u3 V1 v { b. y, J. r
DelayMs(1);
$ N! S$ A. l- T, Y+ R" f sel=sel<<1;
, b; B, J6 S( m$ D$ G1 W% `* }. D# |; c }& \- z# w8 ?( {2 H. [, B, {. L
}
6 S" ?4 U( ?1 X( A2 p5 rvoid xiangshi( int x)//led显示子程序4 ^- u1 z5 b8 h0 w2 N
{! }8 h* B, N8 ?7 `
Data[3]=x/1000;& @0 f" y; R! g- `6 t
Data[2]=x%1000/100;6 J7 i2 J8 a% u) t' F
Data[1]=x%100/10;
. b" s3 r; j3 \: p& g Data[0]=x%10;* e+ V& N8 G F0 B" W2 o$ _
}
; u, T0 P/ Y# o#pragma interrupt_handler jishi:10( ~0 m2 L$ D( P) U! I
void jishi()8 q9 k& x9 f8 Z u; S: d. S' o
{
" E0 _$ I/ E: h h7 S3 e a++;# e) a# Z) \4 W+ Y% x+ \. O
a%=100000;
: |7 d( ~8 M3 c( J$ u5 }4 F- o}
) X. c* V! [6 y( v) X8 dvoid time()) d4 N1 z7 L- Q2 {' t8 i: J
{: y9 V, P X6 B' s
TCCR1B=0X01;+ }- q3 K: J9 l0 D4 n3 H' B5 o
TCNT1H=0X7f;
) h/ `9 ]. O: v TCNT1L=0X9f;
+ k2 ~3 j- q& A' @) @; o5 L TIMSK|=BIT(2);
+ g2 ]0 `$ K# F8 R. A SREG|=BIT(7);
( u w" O: t/ q' b/ U; F! q}
' A% w% J2 N& Q7 mvoid time0()
6 ~6 t1 A4 O; l( r, o7 \{
+ w! e/ T& Q' E' F, D+ l TCCR0=0X04;
! Q4 g: ?) |( W3 m //OCR0=0XFF;) s5 }: t5 J. y4 w6 N& L
TCNT0=0X00;
; r+ y" H1 j2 \0 T% j9 f TIMSK=BIT(1);
) l/ G/ u) w6 g. H+ ~7 |- F" p SREG|=BIT(7);
6 C, I; i4 c; Z& t) U0 q7 I; m}
& y! x @# Y4 hvoid main()6 \( R3 D7 ~& s& a- ?$ V p$ E
{ ; w: O% L! @% D/ l o* K7 M- s
port_init();
# d5 `1 X, a7 G time0();
% w1 P. f$ g2 e0 S+ n //time();6 J4 H/ I! k( C* X1 ?
while(1)( G$ A- v2 d/ [' _7 K! r$ u
{
2 n- A9 f7 M7 G5 l$ B //PORTB&=0XFE;- F, o8 j. W2 H
//delay_us();
5 ^/ K5 p* K: q1 W' x% U //PORTB|=0X01; , p) ?5 e3 @' r) g
// getdata=PINA;
8 @- M& d$ L% ^, Z2 x7 o // }//从P2口读取数据// 3 K, j9 b: V3 A: R7 m9 e
// PORTB&=~BIT(1);//RD=1 使ADC输出数据/ u) h% V- p) q# M/ Z1 f" u; q
xiangshi(a);
$ f# f$ ~" k' u& I2 k Display(Data); //显示//
- E+ T6 }- v1 \- o* m4 v } 6 D# O8 a3 \# }' _" O
}1 X' b8 r# v* {" d$ R9 a1 @
ADC0820.rar$ z g7 W$ g. R1 c% s+ v
tlC0820.part1.rar
9 v( S" `0 T) d I0 ttlC0820.part2.rar |
|