Escolar Documentos
Profissional Documentos
Cultura Documentos
de Programao
em Linguagem C
para 8051
Parte 1
Sumrio
1. Introduo ...................................................................................................................................................................... 1
1.1. Linguagem C ........................................................................................................................................................... 1
1.2. Hardware Base ........................................................................................................................................................ 1
1.3. Estrutura de um Software de Aplicao ................................................................................................................. 2
2. Estrutura Bsica de um programa em C ......................................................................................................................... 3
2.1. PROG1.C Software de Testes ............................................................................................................................. 3
2.2. Comentrios ............................................................................................................................................................ 4
2.3. Diretivas de Pr-Processamento .............................................................................................................................. 4
2.4. Funo Principal void main ( ) ............................................................................................................................. 5
2.5. Atribuies .............................................................................................................................................................. 5
2.6. Loop Infinito while (1) ......................................................................................................................................... 5
2.7. A Linguagem C case sensitive .............................................................................................................................. 5
3. Compilao, Simulao e Programao ......................................................................................................................... 6
3.1. Compilao............................................................................................................................................................. 6
3.1.1. Arquivos .HEX ................................................................................................................................................. 6
3.2. Simulao ............................................................................................................................................................... 7
3.3. Programao na Placa de Testes............................................................................................................................. 7
4. Operadores Lgicos e Aritmticos ................................................................................................................................. 9
4.1. Operadores Lgicos ................................................................................................................................................ 9
4.2. Operadores Aritmticos .......................................................................................................................................... 9
4.3. Exerccios Resolvidos ............................................................................................................................................ 9
4.3.1. EXR1.C ............................................................................................................................................................ 9
4.3.2. EXR2.C ...........................................................................................................................................................10
4.3.3. EXR3.C ...........................................................................................................................................................11
4.3.4. EXR4.C ...........................................................................................................................................................11
4.4. Exerccios Propostos: .............................................................................................................................................12
4.5. Projeto Proposto: ....................................................................................................................................................12
5. Variveis e Funes ......................................................................................................................................................13
5.1. Variveis.................................................................................................................................................................13
5.1.1 Nome ................................................................................................................................................................13
5.1.2 Tipo e Valores ..................................................................................................................................................13
5.2. Funes ..................................................................................................................................................................14
5.2.1 Sintaxe das Funes .........................................................................................................................................14
5.3. PROG2.C Pisca Leds ..........................................................................................................................................15
5.4. PROG3.C Pisca Leds com tempo controlado pela DIPS.....................................................................................15
5.5. Exerccios Resolvidos ...........................................................................................................................................17
5.5.1. EXR5.C ...........................................................................................................................................................17
5.6. Exerccios Propostos: .............................................................................................................................................17
Introduo
1.1. Linguagem C
A Linguagem C foi criada para gerar o menor nmero de cdigos quanto possvel. Seu conjunto de
comandos bem reduzido, porm bastante flexvel.
Para microcontroladores utiliza-se o SDCC (Small Device C Compiler) que um compilador ANSI
C otimizado. Trata-se de um projeto open source (cdigo fonte aberto) sob licena GLP (General
Public License) da GNU.
1.2. Hardware Base
O hardware utilizado no curso a Placa de Testes EDT-044 que utiliza o microcontrolador
AT89S52.
Este microntrolador possui 32 pinos de I/O divididos em 4 ports de 8 bits Estes ports so bit/byte
endereveis, ou seja, podemos acessar o port (P0, P1, P2, P3) ou cada bit individualmente (P0_0,
P0_1, P0_2, P0_3, P0_4, P0_5, P0_6, P0_7, P1_0 ... P1_7, P2_0 ...P2_7, P3_0 ... P3_7).
Na Placa de Testes so utilizadas 9 entradas e 9 sadas, a saber:
Entradas:
P2
Dip-switch com 8 chaves (ON = nvel lgico 0)
P3_2 Push-Bottom (acionada = nvel lgico 0)
Sadas:
P0 8 Leds (ativos em nvel lgico 1)
P3_7 Buzzer (ativo em nvel lgico 0)
P1
P1_0
P1_1
P1_2
P1_3
P1_4
P1_5
P1_6
P1_7
P0_0
P0_1
P0_2
P0_3
P0_4
P0_5
P0_6
P0_7
LED1
LED2
LED3
LED4
LED5
LED6
LED7
LED8
P3
P3_0
P3_1
P3_2
P3_3
P3_4
P3_5
P3_6
P3_7
P2_7
P2_6
P2_5
P2_4
P2_3
P2_2
P2_1
P2_0
DIP8
DIP7
DIP6
DIP5
DIP4
DIP3
DIP2
DIP1
PB
BZ
P0
LEDS
P2
DIPS
INICIO
Declarar e definir
contedos iniciais
das variveis
Inicializar
perifricos
programveis
INICIALIZAO
Colocar contedos
iniciais nas sadas
Processo
LOOP INFINITO
PROG1
Apaga LEDS
Desliga BZ
INICIALIZAO
LOOP INFINITO
LEDS DIPS
BZ PB
Abra o editor JFE (C:\8051\Editor_C\JFE), Carregue o software PROG1.C que est na pasta
C:\8051\CursoC.
A figura a seguir mostra o programa aberto no JFE.
2.2. Comentrios
Os comentrios aparecem em verde e podem iniciados com /* e encerrados com */ quando utilizase vrias linhas ou coloca-se // quando forem colocados em apenas uma linha.
2.3. Diretivas de Pr-Processamento
O comando #include inclui um arquivo header (cabealho) que contm as definies do
microcontrolador utilizado (at89x52.h) assim como bibliotecas com funes em C.
No arquivo at89x52.h tem-se as definies dos ports e registradores de funes especiais do
AT89S52. No momento, utilizaremos somente os ports que aparecem em azul:
P0, P1, P2, P3, P0_0 ... P0_7, P1_0 ... P1_7, P2_0 ...P2_7, P3_0 ... P3_7
Podemos utilizar tambm, os nomes das entradas e sadas da Placa de testes:
As entradas aparecem em marrom:
DIPS, DIP1 ... DIP8 e PB
As sadas aparecem em vermelho:
LEDS, LED1 ... LED8 e BZ
O Apndice B apresenta o arquivo at89x52,h
3.2. Simulao
a)
b)
c)
d)
e)
f)
DIP2
0
1
0
1
LED8
0
0
0
0
LED7
0
0
0
0
LED6
0
0
0
0
LED5
0
0
0
0
LED4
0
1
1
1
LED3
1
0
0
0
LED2
0
0
0
1
LED1
0
1
1
1
Programa EXR1.C
/*
EXR1.C
Exerccio Resolvido 1
Operaes Lgicas
*/
#include <at89x52.h>
void main ()
{
LEDS = 0x00;
BZ = 1;
while (1)
{
LED1 = DIP1 | DIP2;
LED2 = DIP1 & DIP2;
LED3 = !(DIP1 | DIP2);
LED4 = DIP1 | (DIP2 & !DIP1);
}
}
4.3.2. EXR2.C
D uma rotina que apresente nos LEDS o contedo das DIPS multiplicado por 4.
Exemplos de testes:
DIPS
DIP8
DIP7
DIP6
DIP5
DIP4
DIP3
DIP2
DIP1
LEDS
LED8
LED7
LED6
LED5
LED4
LED3
LED2
LED1
0x01
0x05
0x0C
0x3F
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
1
1
0
1
1
1
0
0
0
1
1
1
0
1
0x04
0x14
0x30
0xFC
0
0
0
1
0
0
0
1
0
0
1
1
0
1
1
1
0
0
0
1
1
1
0
1
0
0
0
0
0
0
0
0
Programa EXR2.C
/*
EXR2.C
Exerccio Resolvido 2
Operaes Aritmticas
LEDS = DIPS x 4
*/
#include <at89x52.h>
void main ()
{
LEDS = 0x00;
BZ = 1;
while (1)
{
LEDS = DIPS *4;
}
}
10
4.3.3. EXR3.C
D uma rotina que apresente nos LEDS o contedo das DIPS multiplicado por 4 utilizando
instruo de deslocamento.
Programa EXR3.C
/*
EXR2.C
Exerccio Resolvido 2
LEDS = DIPS x 4
Com instruo de deslocamento
*/
#include <at89x52.h>
void main ()
{
LEDS = 0x00;
BZ = 1;
while (1)
{
LEDS = DIPS << 2;
}
}
4.3.4. EXR4.C
D uma rotina que apresente nos LEDS a soma do nibble mais significativo das DIPS com o nibble
menos significativo.
Algoritmo:
Soma-se o contedo da DIPS deslocado 4 bits direita com o contedo da DIPS com o nibble mais
significativo zerado.
Exemplo: 0x0F + 0x02 = 0x11
DIPS
DIP8
DIP7
DIP6
DIP5
DIP4
DIP3
DIP2
DIP1
DIPS
DIP8
DIP7
DIP6
DIP5
DIP4
DIP3
DIP2
DIP1
0xF2
0x07
0x02
0
0
0
0
0
0
0
0
1
0
1
0
1
1
1
0
LEDS
LED8
LED7
LED6
LED5
LED4
LED3
LED2
LED1
0x11
11
Programa EXR4.C
/*
EXR4.C
Exerccio Resolvido 4
LEDS = soma do nibble mais significativo com o nibble menos significativo da DIPS
*/
#include <at89x52.h>
void main ()
{
LEDS = 0x00;
BZ = 1;
while (1)
{
LEDS = (DIPS >>4) + (DIPS & 0x0F);
}
}
12
5. Variveis e Funes
5.1. Variveis
Uma varivel uma posio de memria na qual o programa pode armazenar valores. Assim, uma
varivel possui 3 atributos: um nome, o tipo de dado e o valor armazenado.
5.1.1 Nome
Algumas regras bsicas para estabelecer o nome da varivel:
a) Deve sempre comear com letra ou sublinhado (_);
b) No pode conter caracteres especiais, somente letras, nmeros e sublinhado;
c) Deve lembrar o que guarda;
d) O compilar C case sensitive;
e) Existem nomes reservados.
Nomes Reservados pelo Padro ANSI-C
auto
else
register
union
break
enum
return
unsigned
case
extern
short
void
char
float
signed
volatile
const
for
sizeof
while
continue
goto
static
main
default
if
struct
do
int
switch
bits
1
8
8
16
16
32
32
32
bytes
1
1
2
2
4
4
4
13
Valores
0 ou 1
-128 a +127
0 a 255
-32768 a +32767
0 a 65355
-2147483648 a +2147483647
0 a 4294967295
1,17549E-38 a 3,402823E+38
double
long
typedef
5.2. Funes
Funes so blocos de programas que so executados como uma sub-rotina.
5.2.1 Sintaxe das Funes
As funes possuem um cabealho e o bloco de instrues que ela realiza como mostra a estrutura
abaixo:
tipo_do_dado_de_retorno nome (declarao_do_parmetro_de_entrada)
{
Instrues;
}
Na declarao da funo, quando ela no retorna nenhum dado coloca-se void (vazio) e, quando no
h nenhum parmetro de entrada no coloca-se nada dentro dos parnteses.
Exemplo1: Funo teste
#include <at89x52.h>
void teste ( )
{
LEDS = DIPS;
BZ = PB;
}
void main ( )
{
LEDS = 0x00;
BZ = 1;
while (1)
{
teste ( );
}
}
Exemplo 2: Funo somar
#include <at89x52.h>
char somar (char a, char b)
{
unsigned char c;
c = a + b;
return (c);
}
void main ( )
{
LEDS = 0x00;
BZ = 1;
while (1)
{
LEDS = somar (0x07,0x20);
}
}
14
DIP2
0
0
1
1
0
0
1
1
DIP1
0
1
0
1
0
1
0
1
VALOR
0
1
2
3
4
5
6
7
T (s)
0,1
0,2
0,3
0,4
0,5
0,6
0,7
0,8
T (ms)
100
200
300
400
500
600
700
800
DIP8
X
0
0
DIP7
X
0
0
DIP6
X
0
0
DIP5
X
0
0
15
DIP4
X
0
0
DIP3
Y
1
Y
DIP2
Y
1
Y
DIP1
Y
1
Y
16
17
LED7
0
1
0
0
0
1
LED6
0
0
1
0
1
0
LED5
0
0
0
1
0
0
LED4
0
0
0
1
0
0
18
LED3
0
0
1
0
1
0
LED2
0
1
0
0
0
1
LED1
1
0
0
0
0
0
LEDS
0x81
0x42
0x24
0x18
0x24
0x42
Forma simplicada:
if (condio)
{
instruo 1;
instruo 2;
...
}
else
{
instruo 1;
instruo 2;
...
}
if (condio) instruo 1;
else instruo 2;
19
Exemplo1:
if ( DIPS = = 0xFF)
{
LEDS = 0xFF;
}
else
{
LEDS = 0x00;
}
Exemplo1
DIPS = 0xFF
Apaga LEDS
DIPS = 0x80
if ( DIPS = = 0x80)
{
BZ = 0;
}
else
{
BZ = 1;
}
Acende LEDS
OU
Desliga BZ
Aciona BZ
Exemplo 2:
if ( PB = = 0 )
{
LED1 = 0;
}
else
{
if ( DIP1 = = 1)
{
LED1 = 1;
}
Exemplo2
PB = 0
Apaga LED1
DIP1 = 1
if ( DIP2 = = 1)
{
LED1 = 1;
}
Acende LED1
}
DIP2 = 1
OU
if ( !PB ) LED1 =0;
else
{
if ( DIP1) LED1 = 1;
if ( DIP2) LED1 = 1;
}
Acende LED1
20
DIP1
0
1
0
1
PROG4
MS (global)
Teste (local)
Apaga LEDS
Desliga BZ
teste= nibble
signif. da DIPS
teste = 0x00
teste = 0x01
teste = 0x02
teste = 0x03
Apaga LEDS
SEQ4( )
SEQ3( )
21
SEQ2( )
SEQ1( )
// FUNES
/*
PROG4.C
SEQUENCIAL DE LEDS
*/
// Diretivas de Pr-Processamento
#include <at89x52.h>
#include <atraso.h>
// Declarao das variveis globais
unsigned int MS = 200;
// Declarao das funes
void SEQ1 ();
void SEQ2 ();
void SEQ3 ();
void SEQ4 ();
// FUNO PRINCIPAL
void main ()
{
// Inicio do programa principal
unsigned char teste; // Declarao de varivel local
LEDS = 0x00;
// Apaga LEDS
BZ = 1;
// Desliga BZ
while (1)
{
// Inicio do Loop Infinito
teste = DIPS & 0x0F;
if (teste==0x00) SEQ1();
else
{
if (teste == 0x01) SEQ2();
else
{
if (teste == 0x02) SEQ3();
else
{
if (teste == 0x03) SEQ4();
else LEDS = 0X00;
}
}
}
}
// Fim do Loop Infinito
}
// Fim do Programa Principal
void SEQ1 ()
{
LEDS = 0xFF;
atraso_ms (MS);
LEDS = 0x00;
atraso_ms (MS);
}
void SEQ2 ()
{
LEDS = 0x55;
atraso_ms (MS);
LEDS = 0xAA;
atraso_ms (MS);
}
void SEQ3 ()
{
LEDS = 0x0F;
atraso_ms (MS);
LEDS = 0xF0;
atraso_ms (MS);
}
void SEQ4 ()
{
LEDS = 0xC0;
atraso_ms (MS);
LEDS = 0x03;
atraso_ms (MS);
LEDS = 0x30;
atraso_ms (MS);
LEDS = 0x0C;
atraso_ms (MS);
}
22
23
24
Forma simplicada:
while (condio)
{
instruo 1;
instruo 2;
...
}
Na estrutura while o bloco de instrues realizado enquanto a condio for verdadeira formando
assim um loop de repetio
Exemplo
PB = 0
S
while ( PB = = 0)
{
BZ = 0;
Atraso_ms(500);
BZ = 1;
Atraso_ms(500);
}
LEDS = 0xFF;
Aciona BZ
Acende os LEDS
Atraso 0,5s
Desliga BZ
Atraso 0,5s
25
Na estrutura do while, realiza-se o bloco de instrues antes de verificar a condio para realizar o
loop de repetio.
Exemplo
Aciona BZ
do
{
Atraso 0,5s
BZ = 0;
Atraso_ms(500);
BZ = 1;
Atraso_ms(500);
Desliga BZ
}
while ( PB = = 0);
LEDS = 0xFF;
Atraso 0,5s
PB = 0
Acende os LEDS
26
PROG6
Apaga LEDS
Desliga BZ
DIP1 = 1
S
teste= nibble +
signif. da DIPS
Acende LED1
teste 0x00
Atraso 5s
Apaga LED8
Apaga LED1
Teste = nibble +
signif. da DIPS
teste 0x00
Acende LED1
Atraso 5s
Apaga LED1
DIP1 = 1
Desliga BZ
Liga BZ
27
Acende LED8
/*
PROG6.C
ALARME RESIDENCIAL
Entradas:
DIP1
= Liga/Desliga Alarme
DIP5 a DIP8 = Sensores
Sadas:
LED1 = Temporizao
LED8 = Sensor ativo
*/
// Diretivas de Pr-Processamento
#include <at89x52.h>
#include <atraso.h>
// FUNO PRINCIPAL
void main ()
{
// Inicio do programa principal
unsigned char teste; // Declarao de varivel local
LEDS = 0x00;
// Apaga LEDS
BZ = 1;
// Desliga BZ
while (1)
{
// Inicio do Loop Infinito
while (!DIP1)
// Espera ligar Alarme
{
teste = DIPS & 0xF0;
// Separa sensores
if (teste != 0x00) LED8=1; // Acende LED8 se sensores <>0
else LED8=0;
// Apaga LED8 se sensores = 0
}
LED1=1;
// Acende LED1
atraso_ms (5000);
// Atraso 5s
LED1=0;
// Apaga LED1
do
{
teste = DIPS & 0xF0;
// Separa sensores
}
while (teste == 0x00);
// Aguarda sensores <> 0
LED1=1;
// Acende LED1
atraso_ms (5000);
// Atraso 5s
LED1=0;
// Apaga LED1
while (DIP1) BZ = 0;
// Aciona BZ enquanto DIP1=1
BZ = 1;
// Desliga BZ
atraso_ms (100);
// Atraso debouncing chave
}
// Fim do Loop Infinito
}
// Fim do Programa Principal
28
Forma simplicada:
for (inicializao;condio;incremento)
{
instruo 1;
instruo 2;
...
}
for (inicializao;condio;incremento)
instruo 1;
29
PROG7
Apaga LEDS
Desliga BZ
PB = 1
Atraso 20ms
PB = 0
Atraso 20ms
CONT +1
LEDS = CONT
DIPS=CONT
S
I=0;i<5;i++
LEDS=CONT
Aciona BZ
Atraso 0,5s
CONT +1
LEDS=0x00
Desliga BZ
Atraso 0,5s
30
/*
PROG7.C
CONTADOR DE EVENTOS
Entradas:
PB = Clock do Contador
DIPS = Programao da Contagem mxima
Sadas:
LEDS = Indicao da Contagem
BZ = Indicao sonora do trmino de Contagem
*/
// Diretivas de Pr-Processamento
#include <at89x52.h>
#include <atraso.h>
// FUNO PRINCIPAL
void main ()
{
// Inicio do programa principal
unsigned char i,CONT =0x00;
// Declarao de varivel local
LEDS = 0x00;
// Apaga LEDS
BZ = 1;
// Desliga BZ
while (1)
{
// Inicio do Loop Infinito
while (PB) {}
// Aguarda PB ir para zero
atraso_ms (20);
// Deboucing
while (!PB) {}
// Aguarda PB ir para um
atraso_ms (20);
// Deboucing
CONT++;
// Incrementa contagem
LEDS = CONT;
// Atualiza LEDS
if (CONT == DIPS)
// Verifica final de contagem
{
for (i=0;i<5;i++)
// Faz 5 bips no BZ
{
LEDS = CONT;
BZ = 0;
atraso_ms (500);
LEDS - 0x00;
BZ = 1;
atraso_ms (500);
}
CONT = 0x00;
// Zera CONT
LEDS = 0x00;
// Zera LEDS
}
}
// Fim do Loop Infinito
}
// Fim do Programa Principal
31
32
8. Atividades no presenciais
a)
b)
c)
d)
33
Apndice A Reviso
Funo OR
S=A|B
A
B
0
0
0
1
1
0
1
1
S
0
1
1
1
Funo AND
S=A&B
A
B
S
0
0
0
0
1
0
1
0
0
1
1
1
Funo XOR
S=A^B
A
B
S
0
0
0
0
1
1
1
0
0
1
1
1
Tabela de Converso
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
Binrio
0
0
0
0
0
1
0
1
1
0
1
0
1
1
1
1
0
0
0
0
0
1
0
1
1
0
1
0
1
1
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
Hexa
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
34
Decimal
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Funo NOT
S = !A
A
S
0
1
1
0
Apndice B at89x52.h
/*------------------------------------------------------------------------Register Declarations for ATMEL 89x52 Processors
Written By - Bernd Bartmann
Bernd.Bartmann@picard.isdn.cs.tu-berlin.de (1999)
based on reg51.h by Sandeep Dutta sandeep.dutta@usa.net
KEIL C compatible definitions are included
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding!
-------------------------------------------------------------------------*/
#ifndef AT89x52_H
#define AT89x52_H
/* BYTE addressable registers */
sfr at 0x80 P0
;
sfr at 0x80 LEDS
;
sfr at 0x81 SP
;
sfr at 0x82 DPL
;
sfr at 0x83 DPH
;
sfr at 0x87 PCON
;
sfr at 0x88 TCON
;
sfr at 0x89 TMOD
;
sfr at 0x8A TL0
;
sfr at 0x8B TL1
;
sfr at 0x8C TH0
;
sfr at 0x8D TH1
;
sfr at 0x90 P1
;
sfr at 0x98 SCON
;
sfr at 0x99 SBUF
;
;
sfr at 0xA0 P2
;
sfr at 0xA0 DIPS
sfr at 0xA8 IE
;
sfr at 0xB0 P3
;
sfr at 0xB8 IP
;
sfr at 0xC8 T2CON
;
sfr at 0xC9 T2MOD
;
sfr at 0xCA RCAP2L
;
35
;
;
;
;
;
;
;
;
/* P1 */
sbit at 0x90 P1_0
sbit at 0x91 P1_1
sbit at 0x92 P1_2
sbit at 0x93 P1_3
sbit at 0x94 P1_4
sbit at 0x95 P1_5
sbit at 0x96 P1_6
sbit at 0x97 P1_7
;
;
;
;
;
;
;
;
sbit at 0x90 T2
;
sbit at 0x91 T2EX
;
/* SCON */
sbit at 0x98 RI
sbit at 0x99 TI
sbit at 0x9A RB8
sbit at 0x9B TB8
sbit at 0x9C REN
;
;
;
;
;
36
;
;
;
/* P2 */
sbit at 0xA0 P2_0
sbit at 0xA1 P2_1
sbit at 0xA2 P2_2
sbit at 0xA3 P2_3
sbit at 0xA4 P2_4
sbit at 0xA5 P2_5
sbit at 0xA6 P2_6
sbit at 0xA7 P2_7
sbit at 0xA0 DIP1
sbit at 0xA1 DIP2
sbit at 0xA2 DIP3
sbit at 0xA3 DIP4
sbit at 0xA4 DIP5
sbit at 0xA5 DIP6
sbit at 0xA6 DIP7
sbit at 0xA7 DIP8
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
/* IE */
sbit at 0xA8 EX0
sbit at 0xA9 ET0
sbit at 0xAA EX1
sbit at 0xAB ET1
sbit at 0xAC ES
sbit at 0xAD ET2
sbit at 0xAF EA
;
;
;
;
;
;
;
/* P3 */
sbit at 0xB0 P3_0
sbit at 0xB1 P3_1
sbit at 0xB2 P3_2
sbit at 0xB2 PB
sbit at 0xB3 P3_3
sbit at 0xB4 P3_4
sbit at 0xB5 P3_5
sbit at 0xB6 P3_6
sbit at 0xB7 P3_7
sbit at 0xB7 BZ
sbit at 0xB0 RXD
sbit at 0xB1 TXD
sbit at 0xB2 INT0
sbit at 0xB3 INT1
sbit at 0xB4 T0
sbit at 0xB5 T1
sbit at 0xB6 WR
sbit at 0xB7 RD
/* IP */
sbit at 0xB8 PX0
sbit at 0xB9 PT0
sbit at 0xBA PX1
sbit at 0xBB PT1
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
37
sbit at 0xBC PS
sbit at 0xBD PT2
;
;
/* T2CON */
sbit at 0xC8 T2CON_0
sbit at 0xC9 T2CON_1
sbit at 0xCA T2CON_2
sbit at 0xCB T2CON_3
sbit at 0xCC T2CON_4
sbit at 0xCD T2CON_5
sbit at 0xCE T2CON_6
sbit at 0xCF T2CON_7
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
0x01
0x02
0x04
0x08
0x80
/* TMOD bits */
#define M0_0
#define M1_0
#define C_T0
#define GATE0
#define M0_1
#define M1_1
#define C_T1
#define GATE1
0x01
0x02
0x04
0x08
0x10
0x20
0x40
0x80
38
#define M0_0_
#define M1_0_
#define C_T0_
#define GATE0_
#define M0_1_
#define M1_1_
#define C_T1_
#define GATE1_
0x01
0x02
0x04
0x08
0x10
0x20
0x40
0x80
#define T0_M0
#define T0_M1
#define T0_CT
#define T0_GATE
#define T1_M0
#define T1_M1
#define T1_CT
#define T1_GATE
0x01
0x02
0x04
0x08
0x10
0x20
0x40
0x80
#define T0_M0_
#define T0_M1_
#define T0_CT_
#define T0_GATE_
#define T1_M0_
#define T1_M1_
#define T1_CT_
#define T1_GATE_
0x01
0x02
0x04
0x08
0x10
0x20
0x40
0x80
#define T0_MASK
#define T1_MASK
0x0F
0xF0
#define T0_MASK_
#define T1_MASK_
0x0F
0xF0
/* T2MOD bits */
#define DCEN
#define T2OE
0x01
0x02
#define DCEN_
#define T2OE_
0x01
0x02
39