Professional Documents
Culture Documents
嵌入式系统开发基础 侯殿有 习题答案
嵌入式系统开发基础 侯殿有 习题答案
(CPU)RAM/ROM
I/O
2?
Embedded
MicroController Unit
Embedded Control System
3, MCS-51 ?
4,
8 16 32
1MCS-51
51 52 51 803180518751
8031 ROM8051
4KB ROM8751 4KB EPROM
2MCS-51
18 CPU
2 128B
3 64KB
4 64KB
5128
621
74 8 I/O
8 16 /
9 5
10
11 1.2M~12M
12+5V
3MCS-51
P0 : P3 P0 P0.0~P0.7 8 I/O
I/O I/O 8 8
A0~A7
P1 P1.0~P1.7 8 MCS-51 I/O
P2 P2.0~P2.7 8 8
A8~A15 16 64K
P3 P3.0~P3.7 8
I/O
4P0 8
ALE ALE
P0 8 A0~A7
ALE
5MCS-51
8 P0
16 64K P0 8
A0~A7 P2
8 A8~A15
P3 RST EA ALE PSEN
6MCS-51 IBM_PC ?
7 EA ?
EA EA =0 EA =1
8MCS-51 ?
MCS-51 RAM SFR
51 128 0X000X7F 128
0X800XFF 52 256 0X000XFF
128 0X800XFF 128
9MCS-51
CPU A B PSW SP
DPTR
P0P3
SCON SBUF PCON
/ TMOD TCON TH0TL0TH1TL1
IE IP
C 2-3
10 803180518751
2 ISP IAP
ISPIn_System Programming
ISPIAPIn-Application Programming FLASH
IAP
FLASH //
1C51 C
C51 C
float double C51
MCS-51
2C51
C51 4-2
3C51 C
C51
(auto)(extern)(static)(register)
4C51
C51 SMALL COMPACT LARGE
5
IBP-PC Keil C51 I/O
C51 51 codedatapdata xdata
8
#define CBYTE((unsigned char volatile*)0x50000L)
#define DBYTE((unsigned char volatile*)0x40000L)
#define PBYTE((unsigned char volatile*)0x30000L)
#define XBYTE((unsigned char volatile*)0x10000L)
#define CWORD((unsigned int volatile*)0x50000L)
#define DWORD((unsigned int volatile*)0x40000L)
#define PWORD((unsigned int volatile*)0x30000L)
#define XWORD((unsigned int volatile*)0x20000L)
absacc.h
#include <absacc.h>
6C51
1
2
3
7C51
8if C51
1if {}
2if { 1} else { 2}
3if 1 { 1}
else if 2 2
else if 3 3
12 val
1dataASCII
char data var
2idata
int idata var
3xdata
unsigned char xdata var
(4) xdatachar
char xdata * var
(5)
bit var
(6)
sbit P1=0x90
(7) P0 bit0
sbit P1_0=P1^0
13 A=3B=4C=5
(1) A+B>C&&B= =C
0
(2) A||B+C&&B-C
1
(3) !(A>B)&&!C||1
1
(4) !(A+B)+C-1&&B+C
1
14
#include<stdio.h>
extern serial_initial();//
main()
{
int x,y ,z;
serial_initial();
printf(input data x,y\n);
scanf (%d,%d,,&x,&y);
printf(\n x y x<y x<=y x>y x>=y x!=y x= =y);
printf(\n);
printf(\n%3d,%3d,x,y);
if z=x<y printf(%5d,z);
else if z=x<=y printf(%5d,z);
else if z=x>y printf(%5d,z);
else if z=x!=y printf(%5d,z);
else if z=x=y printf(%5d,z);
while(1);
}
[reentrant][interrupt m][using n]
2
3 extern
extern
7
1
2
3
1C51
[][={}]
0 0
C51
2C51
C51
char C
\0
\0\0
3C51
5
[] *
C5l
7
C5l
8
6-1
16
9
10
1 8255A
2 8255A
3 8255A C
48255A 8255A 0
A 3
B 2 A B
C A B
C
5 8255A
6 8155
7 8155
8 8155
98155 8155 I/O
8155
1
ABC
A->AB->B->BC->C->CA->A A->AC->C->CB->B->BA->A
13 7-57-6
14 L293L298
1,
CPU
2MCS-51
MCS-51 5 52 6
INT0P3.2 INT1P3.32 / T0 T1 TF0 TF11
( TI RT 1 )
3MCS-51
MCS-51 MCS-51
1
2
4MCS-51
MCS-51
1
2
3 IE0IE1TF0TF1
5MCS-51
TCON
6MCS-51
MCS-51
CPU
CPU
7
RI TI
8 CPU
P1
1/ T0T1
2/ T0T1 TMOD
3/ TCON
4/ T0T1
5/
6 12M 1 6M 1
7
8/
9 T0 2 P1.0 400 S
10:1
400 s P1.0 200 s
12M 1 s 200 s 200 /
2 X=256-200=6 TH0=TL0=56
#include<reg52.h>
sbit P1_0=P1^0;
unsigned char i=0;
//-------------------------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------------------------main()
{
TMOD=0x02;//T0 2
TH0=TL0=56;// 6
EA=1;ET0=1;//T0
TR0=1;// T0
while(1);//
}
//-------------------------------------------------------------------------------------------------------------------// T0 1 T0
//--------------------------------------------------------------------------------------------------------------------
1
2
3MCS51
4 1
5 1 T1
6MCS-51
7TTLRS-232 RS422/RS485
8 10.4
9 TTL/RS232
10 CRC
11
12
#include <stdio.h>
#include "string.h"
#define MAXLEN 1000
void main()
{
int i,j,k,Len;
char ch='\a';
char str[MAXLEN];
char strchars[MAXLEN];
//
for(i=0;i<MAXLEN;i++)
{
str[i]=0;
strchars[i]=0;
}
printf("Please enter a string:\n");
gets(str);
printf("%s\n",str);
Len=strlen(str);
j=0;
for(i=0;i<Len;i++)
{
if(str[i]==' ')
j++;
else break;
}//j
k=0;
for(i=Len-1;i>0;i--)
{
if(str[i]==' ')
k++;
else break;
}//j
for(i=j;i<Len-k;i++)
str[i-j]=str[i];
str[i-j]='\0';
j=0;
k=0;
for(i=0; i<Len; i++)//
{
if(str[i]!=' ')
{
str[j]=str[i];
j++;
k=0;
}
else
{
if(k==0)
{
str[j]=str[i];
j++;
}
k=1;
}
}
str[j]='\0';
puts(str);
13
#include<stdio.h>
#include "string.h"
int Strch(char st[],char ch)
{
int len;
len=strlen(st);
for(int i=0;i<len;i++)
if(ch==st[i])
return i;
return -1;
}
void main()
{
char str[500];
char ch1,ch2;
ch1=',';
ch2='!';
printf("Please enter a string:\n");
gets(str);
fflush(stdin);
printf("%d\n",Strch(str,ch1));
printf("%d\n",Strch(str,ch2));
14
#include <stdio.h>
#include "string.h"
#define MAXLEN 1000
int Strch(char st[],char ch)
{
int len,k;
len=strlen(st);
for(k=0;k<len;k++)
{
if(ch==st[k])
return k;
}
return -1;
}
void main()
{
int i,j,leng;
int count=0;
char str[MAXLEN],str1[MAXLEN],str2[MAXLEN];
//","str1,str2
char ch;
for(i=0;i<MAXLEN;i++)
{
str[i]=0;
str1[i]=0;
str2[i]=0;
}
ch=',';
printf("Please enter a string:\n");
gets(str);
leng=strlen(str);
count=Strch(str,ch);
for(i=0;i<count;i++)
str1[i]=str[i];
j=0;
for(i=count+1;i<leng;i++)
{
str2[j++]=str[i];
}
printf("%d,%d\n",leng,count);
printf("\n");
puts(str1);
printf("\n");
puts(str2);
}
I/O
3 8
4 8 11-2 11-3
58279
6 8279 MCS-51
7 7279
8 11-4 11-5 7279
1A/D
(1) A/D
2 A/D
3 A/D
2A/D
1 2 3 4
3ADC0809 A/D ADC0809
ADC0809 CMOS A/D 8
4ADC0809
ADDAADDBADDC 3 8
5EOC OE
EOCA/D
OE
6
ADC0809 ALE START
7 ADC0809
8AD574 A/D
AD574 12 A/D
AD574 0+10V0+20V-5+5V -10+10V
9AD574 A/D
AD574 12 A/D
10 AD574
11D/A
1
2
3
4
5
12DAC0832
1
2
3
13 DAC0832
12-3
1, I 2 C
SCL SDA
SCL SDA
2 I 2 C
3 I 2 C
4DS12887
DS12887 Dallas
5DS12887 RAM
128 RAM 14
114 RAM RAM
6DS12887
DS12887 128 10 RAM4
114 RAM 128
7 DS12887
8 DS1302 DS1302
9 DS18B20
1LED
288LED
88LED 88LED
3 14-1 88LED ASCII
4 14-2 88LED ASCII
51616LED 88LED
1616 4 88 1616
2 816 4 88 14-6
14-6 4 88
1 2 3 4 1 3 2 4
61616LED
4
7 14-3 1616LED
8 14-3 1616LED
21212161624244848
2424 24 24
4
5 C C
6
7 C
8 1212161624244848
1 T6963C
T6963C
2 T6963C STA0STA1STA2STA3
D7
D6
STA7
D5
STA6
D4
D3
STA5
D2
D1
STA4
D0
STA3
STA2
STA1
STA010
STA110
STA210
STA310
STA4
STA510
STA6/1 0
STA71 0
3 T6963C
0x24
4 T6963C
1
1 1 1 1 N3 N2 N1 N0
STA0
1
N3=1 1N3=0 N2N0D0D7
5 T6963C
2
6
7 1212161624244848
8 16162424
9 88816ASCII
10 4 f
for (x=0;x<160;x++)
{
a=((float)x/159)*4*3.14;
y=sin(a);
b=(1-y)*63;
W_DOT((U8)x,(U8)b);
11
12 T6963C
1, KS0108T6963C?
D0 D7
D7 D0
90 KS0108 T6963C
2KS0108
3KS0108
4KS0108
D0D7
D7D0
90
5~11
588ASCII
6
7 1212161624244848
9 88816ASCII
10 4 f
11
1 HD61830 T6963CKS0108
HD61830 18-3 1616
,
,
1
3 HD61830 T6963C
HD61830 18-3 1616
,
,
y=sin(a);
b=(1-y)*32;
W_DOT((U16)x,(U16)b);
disdelay();
}
8
int i,k,tstch;
unsigned int *p;
p=syb1616+16*chnCODE;// syb1616
for (i=0;i<16;i++)
{
tstch=0x80;
for(k=0;k<8;k++)
{
if(*p>>8&tstch)
W_DOT(x+k,y+i);
if((*p&0x00ff)&tstch)
W_DOT(x+k+8,y+i);
tstch=tstch >>1;
}
p+=1;
}