📄 chap1.c
字号:
// Chapter 1 6811 C programs// Jonathan W. Valvano// This software accompanies the book,// Embedded Microcomputer Systems: Real Time Interfacing// published by Brooks Cole, 1999// Program 1.12. C definitions of some of the MC68HC11 I/O ports.#define PORTA *(unsigned char volatile *)(0x1000)#define PACTL *(unsigned char volatile *)(0x1026)#define PORTB *(unsigned char volatile *)(0x1004) #define PORTC *(unsigned char volatile *)(0x1003)#define DDRC *(unsigned char volatile *)(0x1007)#define PORTD *(unsigned char volatile *)(0x1008)#define DDRD *(unsigned char volatile *)(0x1009)#define PORTE *(unsigned char volatile *)(0x100A)#define PIOC *(unsigned char volatile *)(0x1002)#define TCNT *(unsigned short volatile *)(0x100E)// Program 1.15. C software that reads from port A and writes to port B.// Program to implement a NOT gate// Port A are the 8 digital inputs and Port B are the 8 digital outputs// Software continuously repeats the following// 1) Read value from Port A// 2) Calculate the logical complement// 3) Write the result out to Port B#include "HC11.H"void main(void){ unsigned char data; while(1){ data = PORTA; // Read from Port A data = ~data; // Logical complement PORTB = data; // Write from to Port B}}// Program 1.17. C software that initializes an I/O port to input.// MC68HC11A8 DDRC=0x00;// Program 1.19. C software that reads from an I/O port input.// MC68HC11A8 Happiness=PORTC;// Program 1.21. C software that initializes an I/O port to output.// MC68HC11A8 DDRC=0x0F;// Program 1.23. C software that outputs an I/O port output.// MC68HC11A8 PORTC=0xFF;// Program 1.25. C functions that provide initialization, // read and write access an I/O port.// MC68HC11A8void Init(unsigned char value){ DDRC=value;}void Set(unsigned char value){ PORTC=value;}unsigned char Read(void){ return(PORTC);}// Program 1.28. C programs that implement the 4 bit NOT gate.// HC05C4, HC708XL36, HC11A8, HC812A4void init(void){ DDRC=0xF0;} // PC7-PC4 are outputs, PC3-PC0 are inputsvoid main(void){ unsigned char data; init(); // call ritual once while(1){ data=PORTC; // input data=(~data)<<4; // complement and shift PORTC=data;}} // output
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -