|
这是我自己编的程序 不晓得对不对 请大家帮我看哈 有么问题
) i3 D: W5 M# N' W4 p* T( k程序代码:
' E8 a9 t% R1 T//ICC-AVR application builder : 2009-07-20 9:29:54
- {# d6 h* b4 P+ G! W- b// Target : M16
% ]4 p: S& L' N! o// Crystal: 8.0000Mhz
+ D; O7 W- a' d#include <iom16v.h>/ K6 Y# a: [0 [; u2 B
#include <macros.h>9 O6 c5 ?7 U4 t1 r
//#include <delay.h>
; c o" a. h9 w+ l; O#define uint unsigned int; s* c+ F3 T( t4 ^% R, |; B
#define uchar unsigned char
' l Q: a9 g9 T( w1 A7 {unsigned char Table[11]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x79};
2 g5 d* B! h! w' gunsigned char Data[4]={0,};int getdata;5 `" B4 b1 E9 S# L M
int a;4 {/ [% s7 S, p* l
void DelayMs (unsigned int i)//延时函数 5 d$ B. i, s: {4 o" d
{ . j& o; _: y. J
unsigned int j;: D7 p; h4 X0 z5 T+ ]! x5 x; v
for (;i!=0;i--)
# j# _; S) g8 o6 Z) u for (j=50;j!=0;j--);( U( W. u) A, [1 B/ n) Q
}
/ N9 ~8 R. \% H* |8 H) z$ ]" @! p2 hvoid delay_us() //延时子程序
$ o3 f- ]# d- B) P+ z5 {; I{5 ]1 T" k& G& R4 Z; ^% u1 v/ I
;
, g1 v# I4 I1 I0 e //while(--t);
" O9 X; T+ A$ W}, F. z9 U+ w, h, y
void dly(unsigned int t) X; T5 b. S5 ?* v
{
0 a1 K; l l1 Z$ H5 P ;
7 R; u$ V8 \ p" o/ m6 Y}
2 W/ \- @$ R' i s. b3 G& Gvoid port_init(void)
+ W2 U/ Q# G% T( p k9 d# V: _7 a" |2 r: p{+ M# z3 q2 z* `; K
PORTA = 0xFF;& V% Q- E- r3 f4 c! X; x1 [
DDRA = 0x00;
* z/ K6 l, C: e; g" c) ^$ I PORTB = 0xFb;2 ? G' J3 J* R z( b' r& F* J9 k
DDRB = 0xFB;
8 f' Q: n; k5 t" d+ A3 M PORTC = 0xfF;
4 Y6 A$ n- B4 i: R- P2 _/ W DDRC = 0xfF;
2 P* q2 _# W R4 O% e# y' S PORTD = 0xFF;; {1 p; o6 b2 V) C' G. M( m
DDRD = 0xFF;
G8 x/ X* ~: t. x7 v1 O3 I4 L}
; F' ^, C! W# i2 w( {& [void Display(unsigned char *p)
) V' C4 K) z5 n! z/ Z0 l{# ^9 [: v4 k# K$ S
unsigned sel=0x01,i;
7 u. h/ a2 ^$ l4 e for(i=0;i<4;i++)1 t. q7 M( J$ @+ z7 N4 P6 A% d/ Z
{
8 U6 u6 A5 R# D- {* A PORTC=~sel;3 G% ~! O& |( G Z8 K) U' {, P
PORTD=Table[p[3-i]];9 i. s4 t4 Q* x
DelayMs(1);
6 b1 \/ ^# c8 N& f2 z Z) t7 _ sel=sel<<1;
6 {% L' {/ }; U }/ V0 |: h( {% _2 u/ {0 [
}. F7 g( K+ }8 V8 d
void xiangshi( int x)//led显示子程序
, D. G) h. q- O6 p, _/ Z. s H, z {0 y- j1 O1 A: P7 m: m! M, S
Data[3]=x/1000;
+ T7 s* K( o/ U9 m$ A: J. J Data[2]=x%1000/100;- W8 i! t) L: m7 a# V1 X# Y
Data[1]=x%100/10; ( f: T: }# [8 V: F' K
Data[0]=x%10;- P. w: C. z4 ?- q' E1 u. f( C) N& J* G
}$ g; N. e4 p$ r: \
#pragma interrupt_handler jishi:10
3 h* a% o3 A- k. o' Wvoid jishi()$ }; [. m+ Q1 Z. ]% H
{
8 Y2 v6 q1 B% \ a++;/ D! D8 M- K) ~! Z0 [7 o
a%=100000;5 {% s4 g8 `. i6 {
}
7 m8 h4 G- u2 ?void time()
& o# k% q. ]$ y' Z$ `3 m8 [{
: ~' _% j8 F9 j/ f C. @ X TCCR1B=0X01;
8 ]' A, [8 t: T TCNT1H=0X7f;3 @8 B( k/ W* L& q1 R! L$ N1 u
TCNT1L=0X9f;$ K4 r9 ]# m5 n4 ^
TIMSK|=BIT(2);
( J% y A8 Z9 Q SREG|=BIT(7);
( B7 [7 L4 B* ?$ [! `2 R}
: u% m; t1 Y5 t7 ?3 C6 E) kvoid time0()
4 O8 ], J4 i o{
* g9 l4 j8 @" {# ?- r( b- V6 M+ Z4 X TCCR0=0X04;
: `0 n; F/ X% E //OCR0=0XFF;
$ k% V ?6 i3 \( u7 W6 j" K TCNT0=0X00;/ p/ w& U0 y9 D. G/ H
TIMSK=BIT(1);
I+ K) ?4 v! v: l6 B$ B SREG|=BIT(7);1 C6 u8 n0 s0 h) x
}
5 p2 R2 w$ K8 g: F$ B H! Qvoid main()5 ]+ p* ^4 N! Z: Q% m9 [+ A
{ ( {0 X; x- q/ p7 u- O/ A0 a/ I( @
port_init();! k& \$ p/ S: ?6 }+ S
time0();
& e4 {: e, S& J2 } //time();' [- O) N! v% m, G' n: G
while(1): T1 }( r/ M0 a+ U0 @: m
{
% s( X8 [9 I) @# v5 g" G+ Q/ {7 O+ y //PORTB&=0XFE;- Y* A. D- u; z0 u8 B* L
//delay_us(); $ G& K Y" ~+ S; G- ~
//PORTB|=0X01;
; V7 m; {# M2 w5 U5 C // getdata=PINA; 7 t: E% g) ?! y0 D% Q
// }//从P2口读取数据//
, k! P' O) U* I$ J // PORTB&=~BIT(1);//RD=1 使ADC输出数据9 [" I9 }& k/ a
xiangshi(a);
8 `& D" A* n8 W+ y; j0 _" M' Q Display(Data); //显示// + }% I4 M& R" S+ e* \; g/ h
} - p' v; J- C- L! R
}; `- P4 D9 p" V% c! ?5 V
ADC0820.rar
9 _' t3 y$ p( L% y; ` S8 JtlC0820.part1.rar1 z j! i% Z- k
tlC0820.part2.rar |
|