/*********************************************** LCD Display for E-Gizmo's AC Power Analyzer using PIC16F877A and 20x4 Character LCD This code was made using various codes that can be found from the internet. Do with it whatever you wish at your own risk. By alyas, hunyangongelab@gmail.com***********************************************/// LCD module connectionssbit LCD_RS at RD2_bit;sbit LCD_EN at RD3_bit;sbit LCD_D4 at RD4_bit;sbit LCD_D5 at RD5_bit;sbit LCD_D6 at RD6_bit;sbit LCD_D7 at RD7_bit;sbit LCD_RS_Direction at TRISD2_bit;sbit LCD_EN_Direction at TRISD3_bit;sbit LCD_D4_Direction at TRISD4_bit;sbit LCD_D5_Direction at TRISD5_bit;sbit LCD_D6_Direction at TRISD6_bit;sbit LCD_D7_Direction at TRISD7_bit;// End LCD module connectionsint uart_get_padata() { while (! Uart1_Data_Ready()) {} return Uart1_Read(); }void main(){ char i; char rxbyte; char pa_out[52]; char * range; char * watts; char * va; char * var; char * pf; char * volts; char * amps; Uart1_Init(9600); Delay_Ms(100); Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off lcd_out(1,1,"PF W"); // Format the LCDScreen lcd_out(2,1,"V VA"); // lcd_out(3,1,"A VR"); // while (1) { rxbyte = uart_get_padata(); if (rxbyte = 73) { // Store PA data when starting delimeter "I" is read pa_out[0] = rxbyte; for (i=1; i<53; i++) { rxbyte = uart_get_padata(); pa_out[i] = rxbyte; } range = strtok(pa_out, ","); watts = strtok(0x00, ","); va = strtok(0x00, ","); var = strtok(0x00, ","); pf = strtok(0x00, ","); volts = strtok(0x00, ","); amps = strtok(0x00, ","); lcd_out(1,14,watts); lcd_out(2,15,va); lcd_out(3,14,var); lcd_out(1,4,pf); lcd_out(2,3,volts); lcd_out(3,3,amps); } rxbyte = ""; *pa_out = ""; } }
if (rxbyte = 73) { // Store PA data when starting delimeter "I" is read
Here is my crude but working code using mikroC and PIC16F877A. Convert mo na lang to ZDS, hindi ako marunong nun.Code: [Select] for (i=1; i<53; i++) {
for (i=1; i<53; i++) {
/*********************************************** LCD Display for E-Gizmo's AC Power Analyzer using PIC16F877A and 16x4 Character LCD This code was made using various codes that can be found from the internet. Do with it whatever you wish at your own risk. By alyas, hunyangongelab@gmail.com***********************************************/// LCD module connectionssbit LCD_RS at RD2_bit;sbit LCD_EN at RD3_bit;sbit LCD_D4 at RD4_bit;sbit LCD_D5 at RD5_bit;sbit LCD_D6 at RD6_bit;sbit LCD_D7 at RD7_bit;sbit LCD_RS_Direction at TRISD2_bit;sbit LCD_EN_Direction at TRISD3_bit;sbit LCD_D4_Direction at TRISD4_bit;sbit LCD_D5_Direction at TRISD5_bit;sbit LCD_D6_Direction at TRISD6_bit;sbit LCD_D7_Direction at TRISD7_bit;// End LCD module connectionsint uart_get_padata() { while (! Uart1_Data_Ready()) {} return Uart1_Read(); }void main(){ char i; char rxbyte; char pa_out[52]; char * range; char * watts; char * va; char * var; char * pf; char * volts; char * amps; Uart1_Init(9600); Delay_Ms(100); Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off lcd_out(1,1,"VA:"); // Format the LCDScreen lcd_out(2,1,"V:"); // lcd_out(3,-3,"A:"); // lcd_out(4,-3,"PESO:"); while (1) { rxbyte = uart_get_padata(); if (rxbyte = 73) { // Store PA data when starting delimeter "I" is read pa_out[0] = rxbyte; for (i=1; i<53; i++) { //53 characters being read rxbyte = uart_get_padata(); pa_out[i] = rxbyte; } //end reading /*range = strpbrk(pa_out, ",");*/ watts = strpbrk(pa_out, ","); /*va = strpbrk(pa_out, ","); var = strpbrk(pa_out, ","); pf = strpbrk(pa_out, ",");*/ volts = strpbrk(pa_out, ","); amps = strpbrk(pa_out, ","); lcd_out(1,4,watts); /*lcd_out(2,15,va); lcd_out(3,14,var); lcd_out(1,4,pf);*/ lcd_out(2,3,volts); lcd_out(3,3,amps); } /*rxbyte = ""; *pa_out = "";*/ } }
#define COMMA ','/*cStorage[x]0 - STAT1 - Watts2 - VA3 - VAR4 - PF5 - VOLT6 - AMP*/char cStorage[7][8];void extract(char *data){ int x = 0, y = 0; while(*data){ //Transfer Buffer to Another Variable here cStorage[x][y++] = *data++; if(*data == COMMA){ printf(cStorage[x]); //Send the Parameters through UART x++; y = 0; *data++; } }}void GetPowerData() //Get Power Analyzer Data{ unsigned char ucRcvBuffer[60]; int iCommaCntr = 0, i = 0; if(((ucRcvBuffer[i] = getc()) == 'I')){ //Wait for 'I' to receive while((ucRcvBuffer[++i] = getc())); //Extract Here extract(ucRcvBuffer); memset(ucRcvBuffer,0,sizeof(ucRcvBuffer)); } }
/* 1 2 3 x01234567890123456789012345678901234567890InRange,-0250.6,0010.0,-0150.2,+0.6228,220.39,0.5 */void poll_input(){ unsigned char c; static unsigned char position = 0; unsigned char power_factor; c = getc(); if (c == 'I') /* poll for 'I' in "InRange" */ { position = 0; } else { ++position; if (position == 34) /* wait for the 34th character starting from 'I' */ { power_factor = (c - '6') * 10; /*10s digit of the power factor */ } else if (position == 35) /* wait for the 34th character starting from 'I'*/ { power_factor += (c - '6'); /*add the 1s digit of the power factor*/ /*power factor LED table*/ if (power_factor>=0 && power_factor<=9) { LED = 0b0000; } else if (power_factor>=10 && power_factor<=19) { LED = 0b0001; } else if ..... { ..... } ..... } else if (position > 35) { position = 36; /*prevent overflow rollover to 0*/ } }}
/*********************************************** LCD Display for E-Gizmo's AC Power Analyzer using PIC16F877A and 20x4 Character LCD This code was made using various codes that can be found from the internet. Do with it whatever you wish at your own risk. By alyas, hunyangongelab@gmail.com***********************************************/// LCD module connectionssbit LCD_RS at RD2_bit;sbit LCD_EN at RD3_bit;sbit LCD_D4 at RD4_bit;sbit LCD_D5 at RD5_bit;sbit LCD_D6 at RD6_bit;sbit LCD_D7 at RD7_bit;sbit LCD_RS_Direction at TRISD2_bit;sbit LCD_EN_Direction at TRISD3_bit;sbit LCD_D4_Direction at TRISD4_bit;sbit LCD_D5_Direction at TRISD5_bit;sbit LCD_D6_Direction at TRISD6_bit;sbit LCD_D7_Direction at TRISD7_bit;// End LCD module connectionsint uart_get_padata() { while (! Uart1_Data_Ready()) {} return Uart1_Read(); }void main(){ char i; char rxbyte; char pa_out[52]; char * range; char * watts; char * va; char * var; char * pf; char * volts; char * amps; Uart1_Init(9600); Delay_Ms(100); Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off lcd_out(1,1,"PF W"); // Format the LCDScreen lcd_out(2,1,"V VA"); // lcd_out(3,1,"A VR"); // while (1) { rxbyte = uart_get_padata(); if (rxbyte = 73) { // Store PA data when starting delimeter "I" is read pa_out[0] = rxbyte; for (i=1; i<53; i++) { rxbyte = uart_get_padata(); pa_out = rxbyte; } range = strtok(pa_out, ","); watts = strtok(0x00, ","); va = strtok(0x00, ","); var = strtok(0x00, ","); pf = strtok(0x00, ","); volts = strtok(0x00, ","); amps = strtok(0x00, ","); lcd_out(1,14,watts); //lcd_out(2,15,va); //lcd_out(3,14,var); //lcd_out(1,4,pf); lcd_out(2,3,volts); lcd_out(3,3,amps); } rxbyte = ""; *pa_out = ""; } }