/* * File: 1572_Speedlimiter.c * Author: Hans * * Erstellt am 21.03.2021, 11:11 */ #include #include #include #pragma config FOSC = INTOSC // (INTOSC oscillator; I/O function on CLKIN pin) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled) #pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config PLLEN = OFF // PLL Enable (4x PLL disabled) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LPBOREN = OFF // Low Power Brown-out Reset enable bit (LPBOR is disabled) #pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming) unsigned char var; unsigned char varH; unsigned char varL; unsigned char compare(void); unsigned char Delay_ms( unsigned int i); void __interrupt mein_interrupt(void) { } void main(void) { if(RA3==0)OPTION_REG = 0x72;// PSA = ein, Vorteiler = 1/8 (wenn RA3 auf GND) OSCCONbits.IRCF = 0x0d;//Ozillator = 4MHZ LATA5 = 1; TRISA5 = 0;// Scheinwerfer ein ANSELAbits.ANSA2 = 0;// RA2 ADC Eingang ADCON0bits.CHS = 3;//RA4 ADC Messen ADCON0bits.ADON = 1; ADCON1 = 0x30;//A/D Konversionsfequenz = FRC, VREF an VDD ADCON2bits.TRIGSEL2 = 1;// automatische Konversion, TMR1 triggert T1CONbits.TMR1ON = 1;//ADC Trigger TMR0 = 0; while(1) { Delay_ms(600); var = ADRESH; if(TMR0>=var)LATA5 = 0; TMR0 = 0; } }