Example #1
0
int main(void) {
    Initialize();
    // motor
    OC4RS = 100;
    OC2RS = 100;

    while (1) {
        Get_Inputs();
        Decide();
        // todo: do we even need do outputs?
        // Do_Outputs();
        Timing();
    }

}
Example #2
0
int main()
{
    
  initShadowRegisters();  
    
  TRISC = 0; //RC0 as Output PIN
  //TRISC1 = 0;
  
  
  
  //Clear Analog Inputs and make pins digital pins
  ANSEL=0b00000001;//set RA0 as analog pin
  ANSELH=0;
  
  IRCF0 = 0b111;//set prescaler
  
  UART_Init();
  
  UART_writeString("Startup ... done\n");
  
  
  
  //ADC
    //Select ADC conversion clock Frc
    ADCON1bits.ADCS = 0b111;
     //Configure voltage reference using VDD
    ADCON0bits.VCFG = 0;
    //Select ADC input channel (RA0/AN0)
    ADCON0bits.CHS = 0;
    //Select result format right justified
    //right=1 is good when using all 10 bits the two bytes can be concatenated 
    //easily into an integer
    //left=0 is good when using the 8 most significant bits
    ADCON0bits.ADFM = 1;
    //Turn on ADC module
    ADCON0bits.ADON = 1;
  

        
  
  while(1)
  {
//---------------------------------------------    
    //Blink LED on RC0 and RC1
    SetBitReg(Reg_PORTC,0,HIGH);
    SetBitReg(Reg_PORTC,1,LOW);

    __delay_ms(100); // 100ms Delay

    SetBitReg(Reg_PORTC,0,LOW);
    SetBitReg(Reg_PORTC,1,HIGH);

    __delay_ms(100); // 100ms Delay
//---------------------------------------------        

    
//--------------------------------------------- 
    //UART communication
    while(UART_DataAvailable()>0){
        //char a=UART_ReadByte();
        //UART_writeByte(a);
        //UART_writeByte('\n');
        
        UART_writeNumber(UART_DataAvailable());
        UART_writeByte('\n');  
        
        UART_writeString(UART_ReadString());
        UART_writeByte('\n');
    }
    
    if(UART_DataAvailable()<0){
        UART_writeString("Data Lost Reset UART\n");
        UART_Reset();
    }
    
    //Print a Register
 // UART_writeBitPattern(ANSELH);
 // UART_writeByte('\n');
//---------------------------------------------        

    
//---------------------------------------------    
        
    //Read ADC
    Get_Inputs();
    unsigned int ADC_Value=0;
    
    ADC_Value=ADRESH<<8 | ADRESL;
 
    UART_writeNumber(ADC_Value);
    UART_writeByte('\n');
    
    if(checkBit(ShadowPortC,1)>0)
       SetBitReg(Reg_PORTC,2,HIGH); 
    

 //---------------------------------------------    
  }
  return 0;
  
 
}