<commit_before>/* Main.c file generated by New Project wizard
 *
 * Created:   Thu Mar 3 2016
 * Processor: PIC18F46K22
 * Compiler:  MPLAB C18
 */

#include <p18F46K22.h>
#include <delays.h>
#include <stdio.h>
#include "config.h"
#include "lcd.h"
#include "adc.h"

char line1[16];
char line2[16];
unsigned int t;

void lcdinit();
void lcdstring(unsigned char *);

void msDelay(unsigned int i)
{
    for(; i>0; i--)
        Delay1KTCYx(4);
}

void usDelay(unsigned int i)
{
    for(; i>0; i--)
    {
        Nop();
        Nop();
        Nop();
        Nop();
    }
}

void main(void) {
    unsigned int i;
    short f;
    float msTime=0;
    OSCCON = 0x76;
    VREFCON1 = 0xE0;
    T0CON = 0x01;
    TRISB = 0;
    PORTB = 0xff;
    TRISAbits.TRISA4 = 0;
    TRISBbits.TRISB0 = 1;
    WPUBbits.WPUB0 = 1;
    msDelay(1000);
    lcdinit();
    lcdcmd(0x01);
    lcdcmd(0x80);
    i = 0;
    f=0;
    while(1)
    {
        
        PORTBbits.RB5 = 1;
        TMR0H = 0;
        TMR0L = 0;
        lcdcmd(0x80);
        if(i >= 0x1C)
            f = 1;
        if(i <= 17)
            f = 0; 
        VREFCON2 = i;
        sprintf(line1,"BRIGHT. LVL - %d ",i);
        lcdstring(line1);
        PORTAbits.RA4 = 1;
        Delay10TCYx(4);
        PORTAbits.RA4 = 0;
        while(!PORTBbits.RB0);
        T0CONbits.TMR0ON = 1;
        while(PORTBbits.RB0);
        T0CONbits.TMR0ON = 0;
        t = (TMR0L | (TMR0H << 8));
        lcdcmd(0xC0);
        sprintf(line2,"Time - %i",t);
        lcdstring(line2);
        if(f)
            i--;
        else
            i++;
        PORTBbits.RB5 = 0;<commit_msg>PIR, LDR, Ultrasonic, LED Brightness in Working <commit_after>/* Main.c file generated by New Project wizard
 * Author : <NAME>
 * Created:   Thu Mar 3 2016
 * Processor: PIC18F46K22
 * Compiler:  MPLAB C18
 */

#include <p18f46k22.h>
#include <delays.h>
#include <stdio.h>
#include "config.h"
#include "lcd.h"
#include "adc.h"

// Green LED pin 
#define LED_DIR TRISBbits.TRISB5 
#define LED LATBbits.LATB5

// Ultrasonic Module pin definations
#define US_TRIG_DIR TRISAbits.TRISA4
#define US_TRIG LATAbits.LATA4
#define US_ECHO_DIR TRISBbits.TRISB0
#define US_ECHO PORTBbits.RB0

// PIR Module Pin
#define PIR ANSELAbits.ANSA1

// LDR Pin
#define LDR ANSELAbits.ANSA0

char line1[16];
char line2[16];
unsigned int t;

void lcdinit();
void lcdstring(unsigned char *);

void msDelay(unsigned int i)
{
    for(; i>0; i--)
        Delay1KTCYx(4);
}

void usDelay(unsigned int i)
{
    for(; i>0; i--)
    {
        Nop();
        Nop();
        Nop();
        Nop();
    }
}

void main(void) {
    unsigned int regL, regH, resTMR, resLDR, resPIR;
    short pir_f,i,f;
    OSCCON = 0x76;
    VREFCON1 = 0xE0;
    T0CON = 0x01;
    LED_DIR = 0;
    US_ECHO_DIR = 1;
    US_TRIG_DIR = 0;
    US_ECHO = 1;
    WPUBbits.WPUB0 = 1;
    msDelay(1000);
    lcdinit();
    initADC(0);
    lcdcmd(0x01);
    lcdcmd(0x80);
    i = 0;
    f=0;
    while(1)
    {
        TMR0H = 0;
        TMR0L = 0;
        lcdcmd(0x80);
        if(i >= 0x1C)
            f = 1;
        if(i <= 17)
            f = 0; 
        VREFCON2 = i;
        sprintf(line1,"BRIGHT. LVL - %d ",i);
        lcdstring(line1);
        US_TRIG = 1;
        Delay10TCYx(4);
        US_TRIG = 0;
        while(!US_ECHO);
        T0CONbits.TMR0ON = 1;
        while(US_ECHO);
        T0CONbits.TMR0ON = 0;
        regL = TMR0L;
        regH = TMR0H;
        resTMR = (regH << 8) | regL;
        resLDR = readADC();
        initADC(1);
        resPIR = readADC();
        lcdcmd(0xC0);
        sprintf(line2,"T-%i,P-%i,L-%i",resTMR,resPIR,resLDR);
        lcdstring(line2);
        if(f)
            i--;
        else
            i++;
{'fraction_non_alphanumeric': 0.13864067154075277, 'fraction_numerical': 0.05551042512862172, 'mean_word_length': 1.8724727838258164, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5541998', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1559, 'n_words': 333}