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

📄 as5030.i

📁 as3050 interfacing with atmega8
💻 I
📖 第 1 页 / 共 2 页
字号:
 PORTC.5 = 0;       //------------------------16
 delay_us(1);
 if(PINC.3)
 ANGLE = ANGLE|0x2;  //4
 PORTC.5 = 1;   
 delay_us(1);
 PORTC.5 = 0;       //------------------------17
 delay_us(1); 
 if(PINC.3)
 ANGLE = ANGLE|0x08;  //3
 PORTC.5 = 1;   
 delay_us(1);
 PORTC.5 = 0;       //------------------------18 
 delay_us(1); 
 if(PINC.3)
 ANGLE = ANGLE|0x04;  //2
 PORTC.5 = 1;   
 delay_us(1);
 PORTC.5 = 0;       //------------------------19 
 delay_us(1);
 if(PINC.3)
 ANGLE = ANGLE|0x02; //1
 PORTC.5 = 1;   
 delay_us(1);
 PORTC.5 = 0;       //------------------------20 
 delay_us(1);
 if(PINC.3)
 ANGLE = ANGLE|0x01; //0
 PORTC.5 = 1;   
 delay_us(1);
 PORTC.5 = 0;       //------------------------21 
 delay_us(1);
 
 
//  CLK = 0;
//  command = 0;  
//  for(count = 0;count<5;count++)
//     {DIO = 0;
//      CLK = 0;  
//      delay_us(2);
//      CLK = 1;   
//      delay_us(2); 
//      }   
//    DDRD.0 = 0;  
//    DIO = 1;
//    CLK = 0;  
//    delay_us(10);  
//    C2 = DIO;
//    CLK = 1;  
//    delay_us(10);  
//    CLK = 0;  
//    delay_us(10);
//    LOCK = DIO; 
//    CLK = 1;  
//    delay_us(10);
//    AGC = 0;
//    for(count = 0;count<5;count++)
//     {CLK = 0;  
//      delay_us(10);  
//      if(DIO)
//        {AGC = AGC || 0X01;
//         }
//      CLK = 1;  
//      delay_us(10);    
//         AGC = AGC<<1;       
//      }
//    ANGLE = 0;
//    for(count = 0;count<8;count++)
//     {CLK = 0;  
//      delay_us(10);  
//      if(DIO)
//        {ANGLE = ANGLE || 0X01;
//         }
//      CLK = 1;  
//      delay_us(10);    
//      ANGLE = ANGLE<<1;       
//      }  
//     CLK = 1;    
     delay_us(2);  
     PORTC.2 = 0;
 }
//______________________________________________________________________
void LCDWrite(char LCDData, char RSValue)
{PORTD = LCDData  & 0xF0;  
 PORTB.0  = RSValue;
 PORTB.7                           = 0;
 PORTB.6 = 1;  PORTB.6 = 0;  
 PORTD = (LCDData<<4) & 0xF0; 
 PORTB.0  = RSValue;
 PORTB.6 = 1;  PORTB.6 = 0;    
 PORTC.2 = 1;      
 delay_ms(2); 
 }  
//----------------------------------
void lcd_putsf(char flash *s)
{  while(*s)
   LCDWrite(*s++,1);
}
//---------------------------------- 
void lcd_puts(unsigned char *s)
{  while(*s)
   LCDWrite(*s++,1);
}
//----------------------------------
void LINE1()
{LCDWrite(0X80, 0);        //0x80
}  
//----------------------------------
void LINE2()
{LCDWrite(0XC0, 0);       //0xC0
}  
//----------------------------------
void LINE3()
{LCDWrite(0X94, 0);      //0x14
}  
//----------------------------------
void LINE4()
{LCDWrite(0XD4, 0);      //0X54
}  
//----------------------------------
void LCD_CLEAR()
{LCDWrite(0X01, 0);
}  
//----------------------------------
void LCD_HOME(void)
{LCDWrite(0X10, 0);
}
//----------------------------------
void LCD_CUR_BLINK(void)
{LCDWrite(0X0D, 0);
}
//----------------------------------
void LCD_CUR_OFF(void)
{LCDWrite(0X0C, 0);
}
//----------------------------------
void LCD_CUR_ON(void)
{LCDWrite(0X0E, 0);
}
//----------------------------------
void LCDGotoXY(unsigned char x, unsigned char y)	//Cursor to X Y position
{register unsigned char DDRAMAddr;
 switch(y)
 {case 0: DDRAMAddr = 0x00+x; break;
  case 1: DDRAMAddr = 0x40+x; break;
  case 2: DDRAMAddr = 0x14+x; break;
  case 3: DDRAMAddr = 0x54+x; break;
  default: DDRAMAddr = 0x00+x;
 }
LCDWrite((1<<7| DDRAMAddr),0);
}

//----------------------------------
void lcd_init()
{  PORTB.7                           = 0;
   PORTD = 0;            
   delay_ms(40);
   PORTD = 0X30;          
   PORTB.6 = 1;  PORTB.6 = 0;        
   delay_ms(5);
   PORTB.6 = 1;  PORTB.6 = 0;        
   delay_ms(1);
   PORTB.6 = 1;  PORTB.6 = 0;        
   delay_ms(1);
   PORTD = 0X20;         
   PORTB.6 = 1;  PORTB.6 = 0;
   delay_ms(1);
   LCDWrite(0X28, 0);    
   LCDWrite(0X08, 0);    
   LCDWrite(0X0C, 0);    
   LCDWrite(0X06, 0);    
   LCDWrite(0X0F, 0);    
   LCDWrite(0X80, 0);    
} 
//--------------------------------------------------------
//______________________________________________________________________

//______________________________________________________________________

//-------------------------------------------  
interrupt [9] void timer1_ovf_isr(void)
 {TCNT1H=0x0B;
  TCNT1L=0x00;
  }  
//_______________________________________________________________________

//_____________________________________________________________________________________
void dispfun(unsigned char DispCount)
{
  switch(DispCount)
       {case 0:{LCD_CLEAR();
                LINE1();
                lcd_putsf("GPS REAL TIME CLOCK");
                LINE2();
                lcd_putsf("********************");  
                LINE3();
                lcd_putsf("RUPANAGUDI POWER SYS");
                LINE4();
                lcd_putsf("     HYDERABAD      ");     
                }
                break;
        case 1:{LCD_CLEAR();
                LINE1();
                }
                break; 
        case 2:{LCD_CLEAR();
                LINE1();
                }
                break;          
       case 3:{ LCD_CLEAR();
                LINE1();
                }
                
    }                  
 
 }             
//-------------------------------------------------------------  


// USART Transmitter buffer
char tx_buffer[32];

unsigned char tx_wr_index,tx_rd_index,tx_counter;

// USART Transmitter interrupt service routine
interrupt [14] void usart_tx_isr(void)
{
if (tx_counter)
   {
   --tx_counter;
   UDR=tx_buffer[tx_rd_index];
   if (++tx_rd_index == 32) tx_rd_index=0;
   };
}

// Write a character to the USART Transmitter buffer
#pragma used+
void putchar(char c)
{
while (tx_counter == 32);
#asm("cli")
if (tx_counter || ((UCSRA & (1<<5))==0))
   {
   tx_buffer[tx_wr_index]=c;
   if (++tx_wr_index == 32) tx_wr_index=0;
   ++tx_counter;
   }
else
   UDR=c;
#asm("sei")
}
#pragma used-
 
//_____________________________________________________________
void main(void)
{unsigned char x=0;
 unsigned int count = 0;
PORTB=0x00;
DDRB=0xC1;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0xF0;
TCCR0=0x00;
TCNT0=0x00;
TCCR1A=0x00;
TCCR1B=0x05;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
TIMSK=0x04;  

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 56000
UCSRA=0x00;
UCSRB=0x48;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x08;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

lcd_init();  
dispfun(0);
delay_ms(1000); 
LCD_CUR_OFF();  
DDRC.2 = 1;
DDRC.3 = 0;
DDRC.5 = 1;      
PORTC.5 = 0;
PORTC.3 = 0;
PORTC.2  = 0;
//#asm("sei")
LCD_CLEAR();
LINE1();
lcd_putsf("C2="); 
LINE2();
lcd_putsf("LOCK=");
LINE3();
lcd_putsf("RPM="); 
LINE4();
lcd_putsf("ANGLE=");  
while (1)
{AGC = 0;          
 ANGLE = 0;
 SEND_COMMAND(); 
 if(HIGH)
   {if(ANGLE<200)
      {HIGH = 0;
       }
    }else{if(ANGLE>200)
            {HIGH = 1;
             RPM++; 
             }
          }  

if(++count == 135)
   {count = 0;
    MIN = 1;
//     LCDGotoXY(4,2);       
//     sprintf(buffer,"%d",RPM*60); 
//     lcd_puts(buffer);   
//     printf("              RPM = %d\n",RPM*60); 
    RPM = 0;
    }     
//   LCDGotoXY(3,0);       
//     if(C2)
//      {LCDWrite('1', 1);   
//       }else{LCDWrite('0', 1);
//              }
//     LCDGotoXY(5,1);    
//     if(LOCK)
//      {LCDWrite('1', 1);   
//       }else{LCDWrite('0', 1);
//            }      
//   LCDGotoXY(6,3);       
//   sprintf(buffer,"%d",ANGLE); 
//   lcd_puts(buffer); 
     printf("%d,%d\n",RPM,ANGLE);
 };  //while
}
 /////////////////////////////////////////////////////////////////
         









⌨️ 快捷键说明

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