void main() { Initial(); //Initialize all settings required for general QwikFlash and LCD operation DisplayC(Clear1); //Clear the LCD one time at the beginning of your program DisplayC(Clear2); //Your personal PORT/TRIS/ADCON/etc settings or configurations can go here //Or make your own function and call it TRISBbits.RB0 = 1; // set PortB0 as input port TRISBbits.RB1 = 1; // set PortB1 as input port TRISBbits.RB2 = 1; // set PortB2 as input port TRISBbits.RB3 = 1; // set PortB3 as input port T0CON = 0b00000101; // timer 0 configuration register bit settings INTCON = 0b00110000; // interrupt configuration register bit settings INTCON2 = 0b11110000; // interrupt configuration register 2 bit settings INTCON3 = 0b00001000; // interrupt configuration register 3 bit settings RCON = 0b10000000; TMR0H = 0x67; // Load preload value in timer 0 in high byte TMR0L = 0x69; // Load preload value in timer 0 in low byte INTCONbits.PEIE = 1; // Set PEIE enable bit INTCONbits.GIE = 1; // GIE enable bit T0CONbits.TMR0ON = 1; // turn timer 0 on while (1) { // switch1 is a flag that is set from the low // priority interrupt if (switch1) { DisplayC(pause1); // display the pause symbol Str_2[1] = 0x03; } else { DisplayC(play1); // display the play symbol Str_2[1] = 0x04; } // if switch 1, switch 2, and pushbutton 1 are set // then increment timer if (switch1 == 1 && PORTBbits.RB2 == 1 && PORTBbits.RB3 == 1) { Str_2[7] = '+'; // display ++ for increment Str_2[8] = '+'; timeInDay(); } else { Str_2[7] = ' '; // clear ++ for increment Str_2[8] = ' '; } DisplayC(Str_2); } }
void main() { Initial(); //Initialize all settings required for general QwikFlash and LCD operation DisplayC(Clear1); //Clear the LCD one time at the beginning of your program DisplayC(Clear2); long retTen; // initialize variable for 10K ohm potentiometer long retPot; // initialize variable for Potentiometer 1 on circuit board SSPSTAT = 0b11000000; // SMP and CKE SSPCON1 = 0b00100000; // Enable SPI serial port //Your personal PORT/TRIS/ADCON/etc settings or configurations can go here //Or make your own function and call it while(1) { Delay10KTCYx(25); retTen = tenK(); // Store value from 10K ohm potentiometer Delay10KTCYx(25); retPot = pot1(); // Store value from Potentiometer 1 on circuit board displayAnalog(retTen, retPot); } }
/****************************************************************************** * void mult() * This function multiplies the bits from portB and portC, resulting in integer * values, which are converted to ascii, then are displayed on the LCD. ******************************************************************************/ void mult(unsigned char x, unsigned char y) { unsigned char fnum; unsigned char snum; unsigned char tnum; unsigned char prod; prod = x * y; // multiply bits in portB and portC fnum = prod / 100; // save the first digit in variable fnum snum = prod / 10; // make prod a 2 digit number snum = snum % 10; // save the second digit in variable snum tnum = prod % 10; // save the third digit in variable tnum Str_1[1] = ' '; Str_1[2] = ' '; Str_1[3] = 'B'; Str_1[4] = '*'; Str_1[5] = 'C'; Str_1[6] = '='; Str_2[2] = ' '; Str_2[3] = ' '; Str_2[4] = ' '; Str_2[5] = 48 + fnum; // offset fnum by 48 in order // to display equivalent digit from ascii table Str_2[6] = 48 + snum; // offset snum by 48 in order // to display equivalent digit from ascii table Str_2[7] = 48 + tnum;; // offset tnum by 48 in order // to display equivalent digit from ascii table Str_2[8] = ' '; DisplayC(Str_1); // display characters in first row of LCD DisplayC(Str_2); // display characters in second row of LCD }
/****************************************************************************** * void sub() * This function subtracts the bits in portC from portB resulting in integer * values, which are converted to ascii, then are displayed on the LCD. ******************************************************************************/ void sub(unsigned char x, unsigned char y) { unsigned char fnum; unsigned char snum; int sub; sub = x - y; // subtract portC from portB if (sub >= 0) // if statement for positive numbers { fnum = sub / 10; // save the first digit in variable fnum snum = sub % 10; // save the second digit in variable snum Str_1[1] = ' '; Str_1[2] = ' '; Str_1[3] = 'B'; Str_1[4] = '-'; Str_1[5] = 'C'; Str_1[6] = '='; Str_1[7] = ' '; Str_1[8] = ' '; Str_2[4] = '+'; Str_2[5] = 48 + fnum; // offset fnum by 48 in order // to display equivalent digit from ascii table Str_2[6] = 48 + snum; // offset snum by 48 in order // to display equivalent digit from ascii table Str_2[7] = ' '; Str_2[8] = ' '; DisplayC(Str_1); // display characters in first row of LCD DisplayC(Str_2); // display characters in second row of LCD } else // else for negative numbers { sub = sub * -1; // convert sub to a negative number fnum = sub / 10; // save the first digit in variable fnum snum = sub % 10; // save the second digit in variable snum Str_1[1] = ' '; Str_1[2] = ' '; Str_1[3] = 'B'; Str_1[4] = '-'; Str_1[5] = 'C'; Str_1[6] = '='; Str_1[7] = ' '; Str_1[8] = ' '; Str_2[4] = '-'; Str_2[5] = 48 + fnum; // offset fnum by 48 in order // to display equivalent digit from ascii table Str_2[6] = 48 + snum; // offset snum by 48 in order // to display equivalent digit from ascii table Str_2[7] = ' '; Str_2[8] = ' '; DisplayC(Str_1); // display characters in first row of LCD DisplayC(Str_2); // display characters in second row of LCD } }
void LCDconfig() { // Configure the LCD pins for output LCD_RS_TRIS = 0; //TRISH1 LCD_E_TRIS = 0; //TRISH2 LCD_DATA_TRIS = 0b00001111; // TRISJ, Note the LCD is only on the upper nibble // The lower nibble is all inputs // Initialize the LCD and print to it InitLCD(); DisplayC(LCDRow1); DisplayC(LCDRow2); }
void main() { Initial(); //Initialize all settings required for general QwikFlash and LCD operation DisplayC(Clear1); //Clear the LCD one time at the beginning of your program DisplayC(Clear2); TRISB = 0b00111111; // make portB an input port TRISC = 0b00001111; // make portC an input port //Your personal PORT/TRIS/ADCON/etc settings or configurations can go here //Or make your own function and call it while(1) { unsigned char pB = PORTB; unsigned char pC = PORTC; unsigned char mask = 0b00001111; pB = pB & mask; // mask portB off pC = pC & mask; // mask portC off if((PORTBbits.RB4 == 0) && (PORTBbits.RB5 == 0)) // for add operation { // or multiply operation add(pB, pC); //mult(pB, pC); } if((PORTBbits.RB4 == 0) && (PORTBbits.RB5 == 1)) // for subtract operation { sub(pB, pC); } if((PORTBbits.RB4 == 1) && (PORTBbits.RB5 == 0)) // for AND operation { and(pB, pC); } if((PORTBbits.RB4 == 1) && (PORTBbits.RB5 == 1)) // for NOT operation { not(pB, pC); } } }
/****************************************************************************** * void not() * This function executes the NOT operation for the bits in portB, then displays * the ascii characters 1 or 0 onto the LCD. ******************************************************************************/ void not(unsigned char x, unsigned char y) { Str_1[1] = ' '; Str_1[2] = 'N'; Str_1[3] = 'O'; Str_1[4] = 'T'; Str_1[5] = '('; Str_1[6] = 'B'; Str_1[7] = ')'; Str_1[8] = ' '; Str_2[8] = (!PORTBbits.RB0) + 48; //not operation for bit 0 in portB Str_2[7] = (!PORTBbits.RB1) + 48; //not operation for bit 1 in portB Str_2[6] = (!PORTBbits.RB2) + 48; //not operation for bit 2 in portB Str_2[5] = (!PORTBbits.RB3) + 48; //not operation for bit 3 in portB Str_2[4] = ' '; Str_2[3] = ' '; Str_2[2] = ' '; DisplayC(Str_1); // display characters in first row of LCD DisplayC(Str_2); // display characters in second row of LCD }
/****************************************************************************** * void and() * This function performs the AND operation with the bits from portB and portC, * and displays the ascii characters 1 or 0 onto the LCD. ******************************************************************************/ void and(unsigned char x, unsigned char y) { Str_1[1] = ' '; Str_1[2] = ' '; Str_1[3] = 'B'; Str_1[4] = '&'; Str_1[5] = 'C'; Str_1[6] = '='; Str_1[7] = ' '; Str_1[8] = ' '; Str_2[8] = (PORTBbits.RB0 & PORTCbits.RC0) + 48; // AND operation for bits RB0 and RC0 Str_2[7] = (PORTBbits.RB1 & PORTCbits.RC1) + 48; // AND operation for bits RB1 and RC1 Str_2[6] = (PORTBbits.RB2 & PORTCbits.RC2) + 48; // AND operation for bits RB2 and RC2 Str_2[5] = (PORTBbits.RB3 & PORTCbits.RC3) + 48; // AND operation for bits RB3 and RC3 Str_2[4] = ' '; Str_2[3] = ' '; Str_2[2] = ' '; DisplayC(Str_1); // display characters in first row of LCD DisplayC(Str_2); // display characters in second row of LCD }
/****************************************************************************** * void add() * This function adds the bits from portB and portC resulting in integer * values which are converted to ascii, then are displayed on the LCD ******************************************************************************/ void add(unsigned char x, unsigned char y) { unsigned char fnum; unsigned char snum; unsigned char add; add = x + y; // adds portB and portC fnum = add / 10; // save the first digit in variable fnum snum = add % 10; // save the second digit in variable snum Str_1[1] = ' '; Str_1[2] = ' '; Str_1[3] = 'B'; Str_1[4] = '+'; Str_1[5] = 'C'; Str_1[6] = '='; Str_2[5] = 48 + fnum; // offset fnum by 48 in order // to display equivalent digit from ascii table Str_2[6] = 48 + snum; // offset snum by 48 in order // to display equivalent digit from ascii table Str_2[7] = ' '; Str_2[8] = ' '; DisplayC(Str_1); // display characters in first row of LCD DisplayC(Str_2); // display characters in second row of LCD }
/****************************************************************************** * int pot1() * This function is for the potentiometer that is fixed on the circuit board, * and it converts the value read from the potentiometer, which is analog, and * turns it into two digital values. From there it is displayed onto LCD of the * QwikFlash. ******************************************************************************/ long pot1() { long adLow1; long adHigh1; long addbit1; long addbit2; unsigned char fnum1; unsigned char snum1; unsigned char tnum1; ADCON0 = 0b00100001; // FOSC / 4, Channel 7, A/D module turned on ADCON1 = 0b11000000; // Right justified, FOSC/4 Delay10TCYx(4); ADCON0bits.GO = 1; // Turn on ADC Delay10TCYx(4); adHigh1 = ADRESH; adLow1 = ADRESL; addbit1 = (adHigh1 << 8) + adLow1; // Shift adHighy1 to the left 8 bits // and add adLow1 bits. addbit1 = ((addbit1 * 98) / 1023) + 2; // Make addbit1 a 2 digit value. addbit2 = addbit1; // Store unedited version of addbit1 tnum1 = addbit1 / 100; // Store the third digit in tnum1 addbit1 = addbit1 % 100; fnum1 = addbit1 / 10; // Store the first digit in fnum1 snum1 = addbit1 % 10; // Store the second digit in snum1 Str_2[1] = 'F'; Str_2[2] = 'R'; Str_2[3] = 'E'; Str_2[4] = 'Q'; Str_2[5] = ' '; Str_2[6] = tnum1 + 48; // Add 48 to get the ascii value Str_2[7] = fnum1 + 48; // Add 48 to get the ascii value Str_2[8] = snum1 + 48; ADCON1 = 0b10001110; DisplayC(Str_2); Delay(250); return addbit2; }
/****************************************************************************** * int pot1() * This function is for the 10 Kohm potentiometer and it converts the value * read from the potentiometer, which is analog, and turns it into two digital * values. From there it is displayed onto LCD of the QwikFlash. ******************************************************************************/ long tenK() { long adLow; long adHigh; long addbit; long addbit1; unsigned char fnum; unsigned char snum; TRISEbits.TRISE2 = 1; // Set E2 as an input port. ADCON0 = 0b00111001; ADCON1 = 0b11000000; Delay10TCYx(4); ADCON0bits.GO = 1; Delay10TCYx(4); adLow = ADRESL; adHigh = ADRESH; addbit = (adHigh << 8) + adLow; // Shift adHighy to the left 8 bits // and add adLow bits. addbit1 = (addbit * 5) / 1023; addbit = (addbit * 50) / 1023; // Make addbit a 2 digit value. fnum = addbit / 10; // Store the first digit in fnum snum = addbit % 10; // Store the second digit in snum Str_1[1] = 'A'; Str_1[2] = 'M'; Str_1[3] = 'P'; Str_1[4] = ' '; Str_1[5] = ' '; Str_1[6] = fnum + 48; // Store the first digit in fnum Str_1[7] = '.'; Str_1[8] = snum + 48; // Store the second digit in snum ADCON1 = 0b10001110; DisplayC(Str_1); Delay(250); return addbit1; }
void interrupt My_ISR_High(void) { //interrupt handling for HIGH if (INT0IF == 1 && INT0IE == 1) { seconds = 0; minutes = 0; hours = 0; Str_1[1] = '0'; Str_1[2] = '0'; Str_1[3] = ':'; Str_1[4] = '0'; Str_1[5] = '0'; Str_1[6] = ':'; Str_1[7] = '0'; Str_1[8] = '0'; DisplayC(Str_1); INT0IF = 0; // reset interrupt flag // toggle LEDs on QwikFlash Board if (counter % 2 == 0) { PORTAbits.RA3 = 1; PORTAbits.RA2 = 0; PORTAbits.RA1 = 1; } else { PORTAbits.RA3 = 0; PORTAbits.RA2 = 1; PORTAbits.RA1 = 0; } counter++; } }
/****************************************************************************** * void timeInDay() * This function is used to increment the time from 0 seconds all the way to * 24 hours. Then it resets after a full 24 hours. This function also displays * the time onto the LCD. ******************************************************************************/ void timeInDay(void) { seconds++; if (seconds > 59) { seconds = 0; minutes++; } if (minutes > 59) { minutes = 0; hours++; } if (hours > 23) { hours = 0; } int num1 = seconds / 10; int num2 = seconds % 10; int num3 = minutes / 10; int num4 = minutes % 10; int num5 = hours / 10; int num6 = hours % 10; Str_1[1] = num5 + 48; Str_1[2] = num6 + 48; Str_1[3] = ':'; Str_1[4] = num3 + 48; Str_1[5] = num4 + 48; Str_1[6] = ':'; Str_1[7] = num1 + 48; Str_1[8] = num2 + 48; DisplayC(Str_1); }