Labs/Lab6/Watkins_William_Lab6_Part2.c
// <editor-fold defaultstate="collapsed" desc="Initial()">
/******************************************************************************
 * Initial()
 *
 * This subroutine performs all initializations of variables and registers.
 ******************************************************************************/

Initial()

This subroutine performs all initializations of variables and registers.
Initial () This subroutine performs all initializations of variables and registers .
void Initial() {
    TRISA   = 0b00101001;
    LATA    = 0;
    TRISD   = 0b00001111;
    LATD    = 0;
    TRISC   = 0b10010011;
    LATC    = 0;
    TRISE   = 0b00000000;
    LATEbits.LATE0    = 1;
    LCD_RS_TRIS   = 0;              
    LCD_E_TRIS    = 0;              
    LCD_DATA_TRIS = 0b11000000;     
    LCD_DATA_LAT = 0;               
    ANCON0 = 0b00001001; 
    ANCON1 = 0;
    ANCON2 = 0;
    ADCON0              = 0b00001100;   
    ADCON1bits.VCFG     = 0b00;         
    ADCON1bits.VNCFG    = 0;            
    ADCON2              = 0b10010101;   
    T0CON = 0b00000100;             
    TMR0H = 0x0B;                   
    TMR0L = 0xDC;
    T1CON = 0b00000010;             
    T3CON = 0b00000010;             
    currentCCPR3 = timeON;
    CCP1CON = 0b00001010;       
    CCPTMRS0bits.C1TSEL = 0;    
    CCPR1 = DACInterval;
    CCP3CON = 0b00001010;       
    CCPTMRS0bits.C3TSEL = 0b01; 
    CCPR3X = timeON>>16;
    CCPR3 = timeON;
    TXSTA1 = 0b00100000;            
    RCSTA1 = 0b00010000;            
    BAUDCON1 = 0b01000000;          
    SPBRG1 = 12;                    
    SSP1STATbits.SMP = 1;       
    SSP1STATbits.CKE = 1;
    SSP1CON1bits.CKP = 0;
    SSP1CON1bits.SSPM = 0b0000; 
    RCONbits.IPEN = 1;              
    INTCONbits.GIEL = 1;            
    INTCONbits.GIEH = 1;            
    INTCON2bits.TMR0IP = 0;         
    INTCONbits.TMR0IE = 1;          
    INTCONbits.TMR0IF = 0;          
    IPR1bits.TMR1IP = 0;            
    PIE1bits.TMR1IE = 1;            
    PIR1bits.TMR1IF = 0;            
    IPR2bits.TMR3IP = 0;            
    PIE2bits.TMR3IE = 1;            
    PIR2bits.TMR3IF = 0;            
    IPR3bits.CCP1IP = 0;            
    PIE3bits.CCP1IE = 1;            
    PIR3bits.CCP1IF = 0;            
    IPR4bits.CCP3IP = 0;            
    PIE4bits.CCP3IE = 1;            
    PIR4bits.CCP3IF = 0;            
    IPR1bits.RC1IP = 1;             
    PIE1bits.RC1IE = 1;             
    PIR1bits.RC1IF = 0;             
    IPR1bits.TX1IP = 1;             
    LATD = 0b00100000;          
    T0CONbits.TMR0ON = 1;       
    while(LED_count < 4) {}     
    InitLCD();
    ADCON0bits.ADON = 1;        
    RCSTA1bits.SPEN = 1;        
    SSP1CON1bits.SSPEN = 1;
    LATDbits.LATD4 = 1;
    T1CONbits.TMR1ON = 1;
    T3CONbits.TMR3ON = 1;
}
void Initial ( ) { TRISA = 0b00101001 ; LATA = 0 ; TRISD = 0b00001111 ; LATD = 0 ; TRISC = 0b10010011 ; LATC = 0 ; TRISE = 0b00000000 ; LATEbits . LATE0 = 1 ; LCD_RS_TRIS = 0 ; LCD_E_TRIS = 0 ; LCD_DATA_TRIS = 0b11000000 ; LCD_DATA_LAT = 0 ; ANCON0 = 0b00001001 ; ANCON1 = 0 ; ANCON2 = 0 ; ADCON0 = 0b00001100 ; ADCON1bits . VCFG = 0b00 ; ADCON1bits . VNCFG = 0 ; ADCON2 = 0b10010101 ; T0CON = 0b00000100 ; TMR0H = 0x0B ; TMR0L = 0xDC ; T1CON = 0b00000010 ; T3CON = 0b00000010 ; currentCCPR3 = timeON ; CCP1CON = 0b00001010 ; CCPTMRS0bits . C1TSEL = 0 ; CCPR1 = DACInterval ; CCP3CON = 0b00001010 ; CCPTMRS0bits . C3TSEL = 0b01 ; CCPR3X = timeON >> 16 ; CCPR3 = timeON ; TXSTA1 = 0b00100000 ; RCSTA1 = 0b00010000 ; BAUDCON1 = 0b01000000 ; SPBRG1 = 12 ; SSP1STATbits . SMP = 1 ; SSP1STATbits . CKE = 1 ; SSP1CON1bits . CKP = 0 ; SSP1CON1bits . SSPM = 0b0000 ; RCONbits . IPEN = 1 ; INTCONbits . GIEL = 1 ; INTCONbits . GIEH = 1 ; INTCON2bits . TMR0IP = 0 ; INTCONbits . TMR0IE = 1 ; INTCONbits . TMR0IF = 0 ; IPR1bits . TMR1IP = 0 ; PIE1bits . TMR1IE = 1 ; PIR1bits . TMR1IF = 0 ; IPR2bits . TMR3IP = 0 ; PIE2bits . TMR3IE = 1 ; PIR2bits . TMR3IF = 0 ; IPR3bits . CCP1IP = 0 ; PIE3bits . CCP1IE = 1 ; PIR3bits . CCP1IF = 0 ; IPR4bits . CCP3IP = 0 ; PIE4bits . CCP3IE = 1 ; PIR4bits . CCP3IF = 0 ; IPR1bits . RC1IP = 1 ; PIE1bits . RC1IE = 1 ; PIR1bits . RC1IF = 0 ; IPR1bits . TX1IP = 1 ; LATD = 0b00100000 ; T0CONbits . TMR0ON = 1 ; while ( LED_count < 4 ) { } InitLCD ( ) ; ADCON0bits . ADON = 1 ; RCSTA1bits . SPEN = 1 ; SSP1CON1bits . SSPEN = 1 ; LATDbits . LATD4 = 1 ; T1CONbits . TMR1ON = 1 ; T3CONbits . TMR3ON = 1 ; }
<editor-fold defaultstate="collapsed" desc="Initial()">
 Initial()
<editor - fold defaultstate = " collapsed " desc = " Initial () " > Initial ()
// <editor-fold defaultstate="collapsed" desc="IO Port Config"> // Configure the IO ports // </editor-fold> // <editor-fold defaultstate="collapsed" desc="LCD Config"> // Copied from Lab 6 provided code // Configure the LCD pins for output. Defined in LCDRoutinesEasyPic.h // Register Select Control line // Enable control line  // Note the LCD data is only on the upper nibble RB0:3 // Redundant to line above RB 4:5 for control // RB 6:7 set as inputs for other use, not used by LCD // Initialize LCD data LAT to zero // </editor-fold> // <editor-fold defaultstate="collapsed" desc="ADC Config"> // Configure the ADC to read LM35 first // AN3 and AN1 used // Use channel 3 first // Use Vdd // Use Ground // INSERT // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Timer 0, 1, 3 Config"> // Initializing TMR0 for Initial LED blinks // 16-bit, Fosc / 4, 1:32 prescale // Loading for 0.5s delay // Initializing TMR1 for SPI/DAC output // 16-bit, Fosc/4, no prescale // Initializing TMR3 for Alive LED blink // 16-bit, Fosc/4, no prescale // </editor-fold> // <editor-fold defaultstate="collapsed" desc="CCP Config"> // Variable Config // CCP 1 // Set CCP1 to Compare mode // Set CCP1 Timer to TMR1 // CCP 3 // Set CCP3 to Compare mode // Set CCP3 Timer to TMR3 // </editor-fold> // <editor-fold defaultstate="collapsed" desc="EUSART Config"> // Async, 8N1, 19200 baud, 16MHz, Transmit enable // Async, 8N1, Receive enable // 8-bit mode // Load value of 12 into baud reg - Gives 19230.8 baud // </editor-fold> // <editor-fold defaultstate="collapsed" desc="SPI Config"> // Sample time // SPI Mode 0,0 // Fosc/4 // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Interrupt Config"> // Configuring Interrupts // Enable priority levels // Enable low-priority interrupts to CPU // Enable all interrupts // Timer 0 // Assign low priority to TMR0 interrupts // Enable TMR0 interrupts // Clear the interrupt flag // Timer 1 // Assign low priority to TMR1 interrupts // Enable TMR1 interrupts // Clear the interrupt flag // Timer 3 // Assign low priority to TMR3 interrupts // Enable TMR3 interrupts // Clear interrupt flag // CCP 1 // Assign low priority to CCP1 interrupts // Enable CCP1 interrupts // Clear interrupt flag // CCP 3 // Assign low priority to CCP3 interrupts // Enable CCP3 interrupts // Clear interrupt flag // EUSART 1 // Assign high priority to rx interrupts // Enable EUSART1 Receive interrupts // Clear interrupt flag // Assign high priority to tx interrupts // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Initial LED Sequence"> // Turn on RD5 // Turn on TMR0 // Let sequence run // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Final Config to Start"> // LCD Init // Enable ADC // Turn on ADC // EUSART Comms // Enable Serial port // SPI Communication // Turn on Alive LED // Turn on Timers // </editor-fold>