[an error occurred while processing this directive] [an error occurred while processing this directive]
Я бы сделал несколько иначе(+)
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)
[an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive]

Отправлено AlexD 16 марта 2002 г. 06:37
В ответ на: Работа с регистрами, битами и битовыми полями для Меги103 отправлено Михаил Е. 15 марта 2002 г. 19:49

typedef unsigned char uchar;
typedef signed char schar;
typedef unsigned int uint;

typedef union {
uchar byte;
struct {
uchar bit_0:1;
uchar bit_1:1;
uchar bit_2:1;
uchar bit_3:1;
uchar bit_4:1;
uchar bit_5:1;
uchar bit_6:1;
uchar bit_7:1;
} bit;
} PORT;

__io volatile PORT ADCSR_ @ 0x06; /* ADC Control and Status Register */
#define ADCSR ADCSR_.byte
/* ADC Control and Status Register */
#define aden ADCSR_.bit.bit_7
#define ADEN 0x80
#define adsc ADCSR_.bit.bit_6
#define ADSC 0x40
#define adfr ADCSR_.bit.bit_5
#define ADFR 0x20
#define adif ADCSR_.bit.bit_4
#define ADIF 0x10
#define adie ADCSR_.bit.bit_3
#define ADIE 0x08
#define adps2 ADCSR_.bit.bit_2
#define ADPS2 0x04
#define adps1 ADCSR_.bit.bit_1
#define ADPS1 0x02
#define adps0 ADCSR_.bit.bit_0
#define ADPS0 0x01

Теперь можно так:

ADCSR=0x50;
ADCSR=ADEN|ADPS2|ADPS0;
aden=1;
adsc=0;

а тип PORT, можно использовать не только к портам, но и к любым переменным:

__no_init __regvar PORT flags @ 14;
#define f_PWM_on flags.bit.bit_0
#define f_PWM_ch flags.bit.bit_1

if ( f_PWM_on ) {
// ....
} else {
f_PWM_ch=1;
// ... etс.
}



Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru