/* * Simply a function that prints out a standard welcome message on startup. */ void welcome(void){ Lcd_Clear(); Lcd_Set_Cursor(1,1); Lcd_Write_String(w0); Lcd_Set_Cursor(2,1); Lcd_Write_String(w1); delays(2); }
void LCD_init(void){ Lcd_Init(); Lcd_Clear(); Lcd_Set_XY(0,0); Lcd_Write_String(0,0,"Rw_ECG"); Lcd_Write_String(0,1,"Hello! Your heart rate is: "); Lcd_Write_String(0,4,"---"); }
/*This function takes in 2 arguments, corresponding to what should be displayed on * the 1st and 2nd lines of the LCD screen. * title_item selects which string to display as the title to the menu position. * value_item selects which string to display while changing the submenu item value. */ void LCD_disp(int title_item, int value_item) { char string[LCDL]; Lcd_Clear(); Lcd_Set_Cursor(1,1); Lcd_Write_String(menutitle[title_item]); //Checks if in Manual or Factory mode if (menu_ref_1<=1){ //possibly need to change order of phrases to //include a check for user assist mode, in which case //we check if menu_ref_1 <= 2 // Leo: we don't need to, it does it automatically if (menu_ref_2<=2){ Lcd_Set_Cursor(2,1); sprintf(string, "%s%d%", stringtab[value_item],values[value_item]); Lcd_Write_String(string); } //Statistics //Average: takes the mean of values stored in the IR array else if(menu_ref_2==7){ // unsigned char i; // int total; // int average; // for (i=values[IRSAMPE];i>0;i--){ // total=+IR_samps[i]; //IR_samps defines the array not yet present // } // values[IRAVG]=total/values[IRSAMPE]; // sprintf(string,"%s%d", stringtab[IRAVG], values[IRAVG]); // Lcd_Write_String(string); } else { Lcd_Set_Cursor(2,1); sprintf(string, "%s%d", stringtab[value_item],values[value_item]);//no % symbol Lcd_Write_String(string); } } //To do: Semi auto should have a display of cm from tilt //############################# }
void main(void) { unsigned int a; char *ptr; char str[3] = "LCD"; char str2[] = "MPLAB C18"; TRISD = 0x00; while(1) { Lcd_Clear(); Lcd_Set_Cursor(1,1); ptr = &str[0]; Lcd_Write_String(ptr); Lcd_Set_Cursor(2,1); ptr = &str2[0]; Lcd_Write_String(ptr); Delay10KTCYx(200); Lcd_Clear(); Lcd_Set_Cursor(1,1); Lcd_Write_String("Developed By"); Lcd_Set_Cursor(2,1); Lcd_Write_String("Faintree"); Delay10KTCYx(200); Lcd_Clear(); Lcd_Set_Cursor(1,1); Lcd_Write_String("something"); for(a=0; a<15; a++) { Delay10KTCYx(30); Lcd_Shift_Left(); } for(a=0; a<15; a++) { Delay10KTCYx(30); Lcd_Shift_Right(); } Lcd_Clear(); Lcd_Set_Cursor(2,1); Lcd_Write_Char('e'); Lcd_Write_Char('S'); Delay10KTCYx(300); } }
//////////////////////////////////////////////////////////// // MAIN //////////////////////////////////////////////////////////// void main(void) { // Configura el Oscilador interno a 8Mhz OSCCONbits.IRCF = 0b111; // InitAllLEDs PORTA = 0x00; TRISAbits.TRISA0 = 1; // 1 input TRISAbits.TRISA1 = 1; // 1 input TRISAbits.TRISA2 = 1; // 1 input TRISAbits.TRISA3 = 1; // 1 input // FOR ADC TRISAbits.TRISA4 = 1; // 1 input TRISAbits.TRISA5 = 1; // 1 input // ICSP VPP TRISAbits.TRISA6 = 1; // 1 input // OSCILATOR TRISAbits.TRISA7 = 1; // 1 input // OSCILATOR PORTB = 0x00; //TRISB = 0x00; // 0x00 all as output TRISBbits.TRISB0 = 0; // 0 output TRISBbits.TRISB1 = 0; // 0 output TRISBbits.TRISB2 = 0; // 0 output // FOR LCD_D4 TRISBbits.TRISB3 = 0; // 0 output // FOR LCD_D5 TRISBbits.TRISB4 = 0; // 0 output // FOR LCD_D6 TRISBbits.TRISB5 = 0; // 0 output // FOR LCD_D7 TRISBbits.TRISB6 = 0; // 0 output // PGD (1 is value on POR) & LCD_RS TRISBbits.TRISB7 = 0; // 0 output // PGC (1 is value on POR) & LCD_E //PORTB = 0x00; initADC(); Lcd_Init(); //CMCON = 0x07; while(1) { // INIT ADC CONVERSION initADCConversion(); while(isADCConversionReady() == 0) { ; } int result = getADC10bitResult(); // result = 0-1023 float minValue = 0.0; float maxValue = 5.0; float unitValue = (maxValue-minValue)/1024; // 5.0 / 1024 // Si el voltaje alcanza el máximo valor (Vref+) currentValue=5 y si se queda en el mínimo valor (Vref-) currentValue=0. float currentValue = result * unitValue; //setBCDsText(ftoa(currentValue, (int *) 0)); //setBCDCharacterNumber(integ); Lcd_Clear(); Lcd_Set_Cursor(1,1); Lcd_Write_String(ftoa(currentValue, (int *) 0)); } }
void LCD_disp(int x, int y) { //Probably most important array in commander, note the order int values[7]={max_speed, pid_gain, max_yaw, ir_samp_e, ir_samp_r, ir_raw, ir_avg}; char string[LCDL]; Lcd_Clear(); Lcd_Set_Cursor(1,1); Lcd_Write_String(menutitle[x]); //Display as _string:_value'%'_ sprintf(string, "%s%d%", stringtab[y],values[y]); Lcd_Set_Cursor(2,1); Lcd_Write_String(string); //############################# }
__interrupt void Timer_A(void) { ADC10CTL1 = INCH_7 + ADC10DIV_0; // 选P1.7作为输入 /* * 设置ADC10工作的一些基本参数 * INCH_10: Input channel select, Selects Channel 10 * ADC10DIV_0: ADC10 Clock Divider Select 0 * 这里面没有显示设置ADC10的时钟,但实际上,因为默认0的时候是其内置时钟信号ADC10OSC,所以是设置了的,要查到它的频率: */ ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + REF2_5V; /* * 设置ADC10采样的一些基本参数 * select REF: VR+ = VREF+ and VR- = AVSS * ADC10SHT_3: ADC10 Sample and Hold Time, 64 x ADC10CLKs,这个值意味着什么? * REFON: ADC10 Reference on, 上面是设置,这里是开启,开启需要30us,所以后面紧接着一句等了5个cycles * ADC10ON: ADC10 ON,开启ADC10 */ _delay_cycles(5); // Wait for ADC Ref to settle ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start,开始采样并转换?不是特别理解,是开始工作了的意思吗? _delay_cycles(100);//这里停下来之后是在干什么?是不是ADC10在这个delay的时候工作? ADC10CTL0 &= ~ENC;//停止转换 ADC10CTL0 &= ~(REFON + ADC10ON);//关闭REF和ADC10 heartRaw = ADC10MEM;//从ADC10MEM里面取值 //heartC = (unsigned char)(((heartRaw - 673)*423)>>10); //转换成摄氏温度,最后那个运算是移位运算,没仔细查。 heartC = heartRaw; //UART send while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF=heartC; //到达R波时,亮灯 if (heartC > beatThreshold){ P1OUT = RED_LED; // red LED on } else if(heartC < beatThreshold){ P1OUT = 0; // RED LED off } //计算heart rate,利用是否inpeak来累加心跳次数 if(heartC > beatThreshold && inpeak == 0){ beatCounter++; inpeak = 1; if(beatCounter > 5){ heartRate = 60*500*(beatCounter-1)/counter; Lcd_Write_Int(0,4,heartRate); } else{ Lcd_Write_String(0,4,"---"); } } //退出inpeak else if(heartC < beatThreshold){ inpeak = 0; } //10秒之后全部归零,重新计算 if (counter == 5000){ counter = 0; inpeak = 0; beatCounter = 0; } counter++; }