⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap3.c

📁 摩托罗拉Mc6811利程
💻 C
字号:
// Chapter 3 6811 C programs// Jonathan W. Valvano// This software accompanies the book,// Embedded Microcomputer Systems: Real Time Interfacing// published by Brooks Cole, 1999// Program 3.1. A software function that outputs to a simple printer.void Output(unsigned char LETTER) { unsigned short cnt;    PORT=LETTER;     /* sets Port outputs */    Pulse();         /* pulses GO */    for(cnt=0,cnt<10000,cnt++);   /* Wait for 100 ms */}  // Program 3.2. A software function that inputs from an A/D.unsigned char Input(void); { int dummy;    Pulse();                  /* pulses GO       */    dummy=1000;               /* Wait for 5us    */    return(PORT);             /* Read A/D result */}  // Program 3.4. Assembly language routines to initialize and output to a printer.// MC68HC11A8void Init(void){    PIOC=0x00;}void Out(unsigned char value){unsigned int n;    PORTB=value;    for(n=0;n<28571;n++);}// Program 3.7. 6811 or 6812 C language routine to create an accurate time delay.// 6811 or 6812, numCycles can range from 25 to 32767 void Wait(short numCycles){ short EndT;  // TCNT at the end of the delay    EndT=TCNT+numCycles;     while(EndT-(short)TCNT>0);} // wait until TCNT passes EndT// Program 3.9. C language routines to initialize and read from an A/D.// MC68HC11A8void Init(void){    PIOC=0x01;  // GO=STRB    DDRC=0;}    // PORTC is dataunsigned char In(void){ int n;    PORTB=value; // GO pulse    for(n=0;n<1;n++);    return(PORTC);}// Program 3.11. C language routines to initialize and read from a keyboard.// MC68HC11A8void Init(void){ // PC6-0 is DATAunsigned char dummy;    PIOC=0x02;   // EGA=1    DDRC=0x80;   // STRA=STROBE      PORTC=0x00;  // PC7=0      dummy=PIOC;  dummy=PORTCL;}unsigned char In(void){     while ((PIOC & STAF) == 0);    return(PORTCL); }// Program 3.13. C language routines to initialize and read from an A/D.// MC68HC11A8void Init(void){ // PortC=DATA STRA=DONE STRB=GOunsigned char dummy;    PIOC=0x03;   // EGA=1 INVB=1    DDRC=0x00;   // PC inputs      dummy=PIOC;      dummy=PORTCL;} // clear STAFunsigned char In(void){    PORTB=0;   // GO pulse     while ((PIOC & STAF) == 0);    return(PORTCL); }// Program 3.16. Handshaking C language routines to initialize and read from a sensor.// MC68HC11A8void Init(void){ // PortC=DATA STRA=READY STRB=ACKunsigned char dummy;    PIOC=0x13;   // EGA=1 INVB=1    DDRC=0x00;   // PC inputs      dummy=PIOC;      dummy=PORTCL;} // clear STAFunsigned char In(void){    while ((PIOC & STAF) == 0);    return(PORTCL); }// Program 3.18. Handshaking C language routines to initialize and write to a printer.// MC68HC11A8void Init(void){ // PortC=DATA STRA=READY STRB=START    PIOC=0x1E;   // output handshake    DDRC=0xFF;}  // PC outputs  void Out(unsigned char data){    PORTCL=data;    while ((PIOC & STAF) == 0);}// Program 3.20. C language initialization of the DS1620// MC68HC11A8void Init(void){ // PD5=RST=0    DDRD=0x38;   // PD4=CLK=1    PORTD=0x18;} // PD3=DQ=1// Program 3.22. C language helper functions for the DS1620// MC68HC11A8void out8(char code){ int n;  for(n=0;n<8;n++){     PORTD &= 0xEF;   // PD4=CLK=0     if(code&0x01)         PORTD |= 0x08; // PD3=DQ=1     else       PORTD &= 0xF7; // PD3=DQ=0     PORTD |= 0x10;   // PD4=CLK=1     code = code>>1;}}void start(void){   PORTD |= 0x20;   // PD5=RST=1   out8(0xEE);   PORTD &= 0xDF;}  // PD5=RST=0void stop(void){   PORTD |= 0x20;   // PD5=RST=1   out8(0x22);   PORTD &= 0xDF;}  // PD5=RST=0// Program 3.24. C language functions to set the configuration register on the DS1620// MC68HC11A8void config(char data){   PORTD |= 0x20;   // PD5=RST=1   out8(0x0C);   out8(data);   PORTD &= 0xDF;}  // PD5=RST=0// Program 3.27. C language functions to set the threshold registers on the DS1620// MC68HC11A8void out9(int code){ int n;  for(n=0;n<9;n++){     PORTD &= 0xEF;   // PD4=CLK=0     if(code&0x01)         PORTD |= 0x08; // PD3=DQ=1     else       PORTD &= 0xF7; // PD3=DQ=0     PORTD |= 0x10;   // PD4=CLK=1     code = code>>1;}}void WriteTH(int data){   PORTD |= 0x20;   // PD5=RST=1   out8(0x01);   out9(data);   PORTD &= 0xDF;}  // PD5=RST=0void WriteTL(int data){   PORTD |= 0x20;   // PD5=RST=1   out8(0x02);   out9(data);   PORTD &= 0xDF;}  // PD5=RST=0// Program 3.29. C language functions to read the configuration register on the DS1620// MC68HC11A8unsigned char in8(void){ int n; unsigned char result;  DDRD &= 0xF7; // PD3=DQ input  for(n=0;n<8;n++){     PORTD &= 0xEF;   // PD4=CLK=0     result = result>>1;     if(PORTD&0x08)         result |= 0x80; // PD3=DQ=1     PORTD |= 0x10;}  // PD4=CLK=1   DDRD |= 0x08; // PD3=DQ output   return result;}unsigned char ReadConfig(void){unsigned char value;   PORTD |= 0x20;   // PD5=RST=1   out8(0xAC);   value=in8();   PORTD &= 0xDF;   // PD5=RST=0   return value;}// Program 3.31. C language 9-bit read helper function for the DS1620// MC68HC11A8unsigned int in9(void){ int n; unsigned int result=0;  DDRD &= 0xF7; // PD3=DQ input  for(n=0;n<9;n++){     PORTD &= 0xEF;   // PD4=CLK=0     result = result>>1;     if(PORTD&0x08)         result |= 0x0100; // PD3=DQ=1     PORTD |= 0x10;}  // PD4=CLK=1   DDRD |= 0x08; // PD3=DQ output   return result;}// Program 3.32. C language functions to read the temperatures from the DS1620// MC68HC11A8unsigned int ReadTH(void){unsigned int value;   PORTD |= 0x20;   // PD5=RST=1   out8(0xA1);   value=in9();   PORTD &= 0xDF;   // PD5=RST=0   return value;}unsigned int ReadTL(void){unsigned int value;   PORTD |= 0x20;   // PD5=RST=1   out8(0xA2);   value=in9();   PORTD &= 0xDF;   // PD5=RST=0   return value;}unsigned int ReadT(void){unsigned int value;   PORTD |= 0x20;   // PD5=RST=1   out8(0xAA);   value=in9();   PORTD &= 0xDF;   // PD5=RST=0   return value;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -