void interrupt low_priority InterruptServiceLow(void) { // Check to see what caused the interrupt // (Necessary when more than 1 interrupt at a priority level) // Check for Timer0 Interrupt if (INTCONbits.TMR0IF) { INTCONbits.TMR0IF = 0; // clear (reset) flag // Take an ADC conversion and use it to set Timer0 TMR0H = ADC_Convert(); // MSB from ADC TMR0L = 0; // LSB = 0 // update display variable if (Direction == LEFT2RIGHT) { LED_Display <<= 1; // rotate display by 1 from 0 to 7 if (LED_Display == 0) LED_Display = 1; // rotated bit out, so set bit 0 } else // (Direction == RIGHT2LEFT) { LED_Display >>= 1; // rotate display by 1 from 7 to 0 if (LED_Display == 0) LED_Display = 0x80; // rotated bit out, so set bit 7 } }
int main() { MCU_Init(); Timer1_Init(); Timer2_Init(); IO_Init(); ADC_Init(); Timer1_ON; //start 16 bit timer1 Timer2_ON; //start 16 bit timer2 ADC_ON; //turns on ADC module while(1) { ADC_Convert(); } }
void main(void) { uchar display[6]; WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer Clock1MHZ_Init(); ADC10_Init(); LCD1602_Init(); TLC5615_Init(); Button_Init(); __enable_interrupt(); ADC10_Enable(); while(1) { TLC5615_Convert((uint)(DA_Output * 512 / 3.555f)); __delay_cycles(50000); NumberToString(display, ADC_Convert(ADC_Value[0])); LCD1602_Show(0, 0, display); __delay_cycles(50000); } }
void main (void) { LEDDirections Direction = LEFT2RIGHT; BOOL SwitchPressed = FALSE; LED_Display = 1; // initialize // Init I/O TRISD = 0b00000000; // PORTD bits 7:0 are all outputs (0) TRISAbits.TRISA0 = 1; // TRISA0 input INTCON2bits.RBPU = 0; // enable PORTB internal pullups WPUBbits.WPUB0 = 1; // enable pull up on RB0 // ADCON1 is now set up in the InitADC() function. TRISBbits.TRISB0 = 1; // PORTB bit 0 (connected to switch) is input (1) // Init Timer0 Timer0_Init(); // Init ADC ADC_Init(); while (1) { if (Direction == LEFT2RIGHT) { LED_Display <<= 1; // rotate display by 1 from 0 to 7 if (LED_Display == 0) LED_Display = 1; // rotated bit out, so set bit 0 } if (Direction == RIGHT2LEFT) { LED_Display >>= 1; // rotate display by 1 from 7 to 0 if (LED_Display == 0) LED_Display = 0x80; // rotated bit out, so set bit 7 } LATD = LED_Display; // output LED_Display value to PORTD LEDs do { // poll the switch while waiting for the timer to roll over. if (Switch_Pin == 1) { // look for switch released. SwitchPressed = FALSE; } else if (SwitchPressed == FALSE) // && (Switch_Pin == 0) due to if-else { // switch was just pressed SwitchPressed = TRUE; // change direction if (Direction == LEFT2RIGHT) Direction = RIGHT2LEFT; else Direction = LEFT2RIGHT; } } while (INTCONbits.TMR0IF == 0); // Timer expired INTCONbits.TMR0IF = 0; // Reset Timer flag // Take an ADC conversion and use it to set Timer0 TMR0H = ADC_Convert(); // MSB from ADC TMR0L = 0; // LSB = 0 }