No output after load program

Programmer, In-Circuit Debugger, PIC Start-Up Kit, Memory Interface...

Re: No output after load program

Postby karthi06 » Mon Mar 10, 2014 9:27 pm

The coding for the project,as shown below:
CODE: SELECT_ALL_CODE
#define Hi(param) ((char *)&param)[1]
#define Lo(param) ((char *)&param)[0]
#define Higher(param) ((char *)&param)[2]
#define Highest(param) ((char *)&param)[3]

// LCD module connections
sbit LCD_RS at LATD0_bit;
sbit LCD_EN at LATD1_bit;
sbit LCD_D4 at LATD2_bit;
sbit LCD_D5 at LATD3_bit;
sbit LCD_D6 at LATD4_bit;
sbit LCD_D7 at LATD5_bit;

sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// End LCD module connections

// NMEA Library RX1 Interrupt flag
sbit NMEA_IntFlag at RC1IF_bit;

// GSM_GPRS Library RX2 Interrupt flag
sbit GSM_RST at LATC0_bit;
sbit UARTIntEn at RC2IE_bit;
sbit TimerIntEn at TMR1IE_bit;
sbit TimerIntFlg at TMR1IF_bit;

#define UART1_baudrate 9600
#define UART2_baudrate 9600

// Mobile Number Length (Should be Mobile number length + 1
#define MobileNoLen 12

#define GSM_GPS_BUFF_SZ 90

// Constant Strings for GSM

const char at1[]      = "AT\r";
const char atCCLK[]   = "AT+CCLK?\r";
const char atCMGF[]   = "AT+CMGF=1\r";
const char atCMGS[]   = "AT+CMGS=\"";
const char prompt[]   = "> ";
const char msg1[]     = "I am Mr.Karthigan Dasaratha. I have involved in an accident at ";
const char msg2[]     = ", with 4 passengers in Car no. ";
const char msg3[]     = "JJS 4543, Honda Civic Type-R.";
const char response[] = "OK";
const char err[]      = "ERROR";

// Constant Strings for LCD
const char msg4[14]   = "Enter No. ";
const char eepMsg1[]  = "Saving Number...";
const char eepMsg2[]  = "Number Saved... ";
const char eepMsg3[]  = "Reading memory..";
const char eepMsg4[]  = "Memory read...  ";

char rcvd = 0, count = 0, crash = 0, toggle = 0, readCount = 0, sent = 0;

char tempBuff[6];
char buff[70];
char CC2RamBuff[30];
char gsm_gps_buff[GSM_GPS_BUFF_SZ];
char nmea[GSM_GPS_BUFF_SZ];
char latitude[25];
char longitude[25];
char temp[40];
char tmp[2];
char strKey[17];
char key[16];

char mobileNo[4][MobileNoLen];

unsigned char noSet[4] = {0, 0, 0, 0};

unsigned char tmpCnt = 0, set = 0, readKeys = 0, noCount = 0, store = 0, addr = 0, cnt = 0, idx = 0;

unsigned int buffIndex = 0, i = 0, j = 0, k = 0, timer = 0, sec = 1000, keyVal = 0, resetCnt = 0, failIndex = 0, sentFail = 0;
unsigned int eepCnt = 0;
unsigned int time = 0, time2Count = 0, attemptFlag = 0;

signed int keyCount = 0;

// Callback function called on reception of NMEA sentence
void NMEA_DataReceived() {
        rcvd = 1;
}

//Timer1
//Prescaler 1:8; TMR1 Preload = 3035; Actual Interrupt Time : 100 ms

//Place/Copy this part in declaration section
void InitTimer1() {
    T1CON = 0x31;
    TMR1IF_bit = 0;
    TMR1H = 0x0B;
    TMR1L = 0xDB;
    TMR1IE_bit = 1;
}

void Interrupt() {

     if(RC1IF_bit) {
          NMEA_IntHandler();
     }

     if(RC2IF_bit) {
          gsm_gps_buff[buffIndex++] = UART2_Read();
          gsm_gps_buff[buffIndex] = '\0';
          RC2IF_bit = 0;
     }

     if(INT0IF_bit) {
           crash = 1;
           INT0IF_bit = 0;
     }

     if(TMR1IF_bit) {
     
            if(!crash) {
                  if(++timer == 40){
                         timer = 0;
                         toggle = ~toggle;
                  }
            }
            else if(crash)++time;
           
            TMR1IF_bit = 0;
            TMR1H = 0x0B;
            TMR1L = 0xDB;
     }
}

void Delay2Sec() {
     Delay_ms(2000);
}


void main() {

     ANSELA = 0x01;
     ANSELB = 0x00;
     ANSELC = 0x00;
     ANSELD = 0x00;
     ANSELE = 0x00;
     
     ADCON1 = 0x80;
     ADCON2 = 0xB6;
     
     CM1CON0 = 0x00;
     CM2CON0 = 0x00;
     
     VREFCON0= 0x00;
     
     TRISA = 0xFF;
     TRISB = 0xFF;
     TRISC = 0xC0;
     TRISD = 0xC0;
     TRISE = 0x80;
     
     PORTA = 0x00;
     PORTB = 0x01;
     PORTC = 0x00;
     PORTD = 0x00;
     PORTE = 0x80;
     
     LATA = 0x00;
     LATB = 0x00;
     LATC = 0x00;
     LATD = 0x00;
     LATE = 0x00;

     INTCON = 0xD0;
     INTCON2.INTEDG0 = 0;
     
     LCD_Init();
     LCD_Cmd(_LCD_CURSOR_OFF);
     LCD_Cmd(_LCD_CLEAR);
     
     Delay_ms(500);
     
     LCD_Out(1,5,"Accident");
     LCD_Out(2,5,"Notifier");

     set = EEPROM_Read(0x00);
     Delay_ms(20);
     crash = EEPROM_read(0x01);
     Delay_ms(20);
     sent = EEPROM_read(0x02);
     Delay_ms(20);
     
     if(set == 'S'){
     
           for(i = 0; i < 4; i++){
           
                  switch(i){
                        case 0:
                             addr = 0x03;
                             break;
                        case 1:
                             addr = 0x0F;
                             break;
                        case 2:
                             addr = 0x1A;
                             break;
                        case 3:
                             addr = 0x25;
                             break;
                  };
                 
                  LCD_Cmd(_LCD_CLEAR);
                  LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, eepMsg3));
                  Delay2Sec();
                  eepCnt = addr + 12;
                  k = 0;
                  for(j = addr; j < eepCnt; j++){
                          mobileNo[i][k] = EEPROM_Read(j);
                          k++;
                          Delay_ms(50);
                  }
                 
                  mobileNo[i][j] = '\0';

                  LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, eepMsg4));
                  Delay2Sec();
                 
                  cnt = 0;
                 
           }
           
           i = 0;
           j = 0;
           LCD_Cmd(_LCD_CLEAR);
           LCD_Out(1,1,mobileNo[1]);
           LCD_Out(2,1,mobileNo[2]);
     }

     UART1_Init(UART1_baudrate);
     Delay_ms(200);

     UART2_Init(UART2_baudrate);
     Delay_ms(200);

     NMEA_Init(&UART1_Read, gsm_gps_buff, sizeof(gsm_gps_buff));

     InitTimer1();

     while(1) {

             keyVal = ADC_Read(0);

             if((keyVal >= 475) && (keyVal <= 495) && (readKeys == 0)) {
                    Delay_ms(200);
                    keyVal = ADC_Read(0);
                    if((keyVal >= 475) && (keyVal <= 495) && (readKeys == 0)) {
                            readKeys = 1;
                            LCD_Cmd(_LCD_CLEAR);
                    }
             }

             while(readKeys) {
             
                    keyVal = 0;
                    keyVal = ADC_Read(0);
                    Delay_ms(200);
                    keyVal = ADC_Read(0);
                   
                    switch(noCount) {
                        case 0:
                              LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, msg4));
                              LCD_Out(1,11,"1");
                              break;
                        case 1:
                              LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, msg4));
                              LCD_Out(1,11,"2");
                              break;
                        case 2:
                              LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, msg4));
                              LCD_Out(1,11,"3");
                              break;
                        case 3:
                              LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, msg4));
                              LCD_Out(1,11,"4");
                              break;
                    };
                   
                    while((keyVal >= 375) && (keyVal <= 735)) {
                   
                              if((keyCount >= 0) && (keyCount < 11)) {
                                    if(keyCount != 3) {
                                          Get_Key(&key, keyVal, 445, 465, &keyCount, '0', '+');
                                          Get_Key(&key, keyVal, 590, 605, &keyCount, '1', '+');
                                          Get_Key(&key, keyVal, 570, 585, &keyCount, '2', '+');
                                          Get_Key(&key, keyVal, 550, 565, &keyCount, '3', '+');
                                          Get_Key(&key, keyVal, 665, 675, &keyCount, '4', '+');
                                          Get_Key(&key, keyVal, 650, 662, &keyCount, '5', '+');
                                          Get_Key(&key, keyVal, 635, 648, &keyCount, '6', '+');
                                          Get_Key(&key, keyVal, 720, 730, &keyCount, '7', '+');
                                          Get_Key(&key, keyVal, 710, 718, &keyCount, '8', '+');
                                          Get_Key(&key, keyVal, 695, 708, &keyCount, '9', '+');
                                    }
                                    if(keyCount == 3)
                                          Get_Key(&key, keyVal, 685, 700, &keyCount, '-', '+');
                              }

                              if((keyVal >= 378) && (keyVal <= 390)) {   //+
                                      if(++noCount > 3)noCount = 0;
                                      clrbuff(&memset, key, '\0', 16);
                                      LCD_Cmd(_LCD_CLEAR);
                                     
                                      switch(noCount) {
                                          case 0:
                                                LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, msg4));
                                                LCD_Out(1,11,"1");
                                                break;
                                          case 1:
                                                LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, msg4));
                                                LCD_Out(1,11,"2");
                                                break;
                                          case 2:
                                                LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, msg4));
                                                LCD_Out(1,11,"3");
                                                break;
                                          case 3:
                                                LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, msg4));
                                                LCD_Out(1,11,"4");
                                                break;
                                      };
                                      keyCount = 0;
                              }
                              else if((keyVal >= 530) && (keyVal <= 545)) {  //-
                                          Get_Key(&key, keyVal, 530, 545, &keyCount, ' ', '-');
                                          LCD_Out(2,1,"                ");
                              }
                              else if((keyVal >= 625) && (keyVal <= 633)) {  //*
                                          if(keyCount == 11)store = 1;
                              }
                             
                              LCD_Out(2,1,key);
                              if(keyCount == 11){store = 1; Delay_ms(1000); }
                              keyVal = 1022;

                              if(store) {
                             
                                      switch(noCount) {
                                            case 0:
                                                  addr = 0x03;
                                                  noSet[0] = 1;
                                                  break;
                                            case 1:
                                                  addr = 0x0F;
                                                  noSet[1] = 1;
                                                  break;
                                            case 2:
                                                  addr = 0x1A;
                                                  noSet[2] = 1;
                                                  break;
                                            case 3:
                                                  addr = 0x25;
                                                  noSet[3] = 1;
                                                  break;
                                      };
                                     
                                      idx = 0;
                                      tmpCnt = addr;
                                      LCD_Cmd(_LCD_CLEAR);
                                      LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, eepMsg1));
                                      Delay_ms(2000);
                                      for(cnt = tmpCnt; cnt < (addr + 12); cnt++){
                                              EEPROM_Write(cnt, key[idx]);
                                              Delay_ms(20);
                                      }
                                     
                                      store = 0;
                                      keyCount = 0;
                                      ++noCount;
                                      LCD_Cmd(_LCD_CLEAR);
                                      LCD_Out(1,1,CopyConst2Ram(CC2RamBuff, eepMsg2));
                                      Delay_ms(2000);
                              }

                              if((noSet[0]) && (noSet[1]) && (noSet[2]) && (noSet[3])) {
                                          EEPROM_Write(0x00, 'S');
                                          Delay_ms(20);
                                          readKeys = 0;
                                          _asm{
                                               reset
                                          }
                              }
                    }
             }

             if(set == 'S') {
             
                   if(!crash) {
                         if(toggle){
                              LCD_Out(1,1,mobileNo[1]);
                              LCD_Out(2,1,mobileNo[2]);
                         }
                         else if(!toggle) {
                              LCD_Out(1,1,mobileNo[3]);
                              LCD_Out(2,1,mobileNo[4]);
                         }
                   }
                   else if(crash) {
                        TMR1IE_bit = 0;
                       
                        EEPROM_Write(0x01, crash);
                        Delay_ms(20);

                        i = 0;
                        j = 0;

                        sent = EEPROM_Read(0x02);
                        Delay_ms(20);
                       
                        if(sent == 0xFF) {
                              RC1IE_bit = 1;

                              // wait until valid position is acquired
                              while(1) {
                                 if(rcvd) {
                                    strcpy(nmea, gsm_gps_buff);
                                    if((NMEA_IsValid(nmea)) && (strstr(nmea, "$GPGGA"))) {
                                           NMEA_Split(tmp, nmea, ',', 6);   // 0 = not fixed, 1 or 2 = fixed
                                           if(tmp[0] == '1' || tmp[0] == '2'){
                                              if(++readCount == 4){readCount = 0; PORTC.F0 = 1; break;}  // position locked, exit here from while(1)
                                           }
                                    }
                                    rcvd = 0;
                                 }
                              }

                              RC1IE_bit = 0;
                              rcvd = 0;

                              NMEA_Split(latitude, nmea, ',', 2);

                              for(i = 0; i < strlen(latitude); i++){
                                      EEPROM_Write((0x60 + i), latitude[i]);
                                      Delay_ms(20);
                              }

                              NMEA_Split(tmp, nmea, ',', 3);

                              EEPROM_Write(0x90, tmp[0]);
                              Delay_ms(20);

                              strcat(latitude, tmp);

                              NMEA_Split(longitude, nmea, ',', 4);

                              for(i = 0; i < strlen(longitude); i++){
                                      EEPROM_Write((0x70 + i), longitude[i]);
                                      Delay_ms(20);
                              }

                              NMEA_Split(tmp, nmea, ',', 5);

                              EEPROM_Write(0x91, tmp[0]);
                              Delay_ms(20);
                       
                              strcat(longitude, tmp);
                             
                              EEPROM_Write(0x02, 0x01);
                              Delay_ms(20);
                        }
                        else if(sent == 0x01) {
                                j = 0;
                                for(i = 0x60; i < 0x6F; i++){
                                      if(EEPROM_Read(i) != 0xFF){
                                               latitude[j++] = EEPROM_Read(i);
                                               Delay_ms(20);
                                      }
                                }
                                latitude[j] = '\0';
                                j = 0;
                                for(i = 0x70; i < 0x7F; i++){
                                      if(EEPROM_Read(i) != 0xFF){
                                               longitude[j++] = EEPROM_Read(i);
                                               Delay_ms(20);
                                      }
                                }
                                longitude[j] = '\0';
                                j = 0;
                                tmp[0] = EEPROM_Read(0x90);
                                tmp[1] = '\0';
                                strcat(latitude, tmp);
                       
                                tmp[0] = EEPROM_Read(0x91);
                                strcat(longitude, tmp);
                        }
                       
                        for(j = 0; j < 4; j++) {

                                 if(sentFail){
                                       j = failIndex;
                                       sentFail = 0;
                                 }

                                 GSM_Send_AT_Cmd1(&UART2_Write_Text, gsm_gps_buff, 90, response, at1, err, CC2RamBuff, 30, 2, &buffIndex, &attemptFlag, &time2Count, &time, &memset, &strstr, &CopyConst2Ram);
                                 GSM_Send_AT_Cmd1(&UART2_Write_Text, gsm_gps_buff, 90, response, atCMGF, err, CC2RamBuff, 30, 2, &buffIndex, &attemptFlag, &time2Count, &time, &memset, &strstr, &CopyConst2Ram);

                                 strcat(temp, CopyConst2Ram(gsm_gps_buff, atCMGS));
                                 strcat(temp, mobileNo[j]);
                                 strcat(temp, "\"");

                                 while(strstr(gsm_gps_buff, CopyConst2Ram(tempBuff, prompt)) == 0) {
                                            UARTIntEn = 1;
                                            UART2_Write_Txt(&UART2_Write_Text, temp);
                                            Delay_ms(3000);
                                            UARTIntEn = 0;
                                            buffIndex = 0;
                                 }
                                 
                                 clrbuff(&memset, gsm_gps_buff, '\0', 90);

                                 UART2_Write_ConstTxt(&UART2_Write_Text, &CopyConst2Ram, gsm_gps_buff, msg1);
                                 clrbuff(&memset, gsm_gps_buff, '\0', 90);
                                 UART2_Write_Txt(&UART2_Write_Text, latitude);
                                 UART2_Write_Text(", ");
                                 UART2_Write_Txt(&UART2_Write_Text, longitude);
                                 UART2_Write_ConstTxt(&UART2_Write_Text, &CopyConst2Ram, CC2RamBuff, msg2);
                                 UART2_Write_ConstTxt(&UART2_Write_Text, &CopyConst2Ram, CC2RamBuff, msg3);
                                 UARTIntEn = 1;
                                 Delay_ms(500);
                                 UART2_Write(0x1A);
                                 Delay_ms(6000);
                                 if(strstr(gsm_gps_buff, CopyConst2Ram(CC2RamBuff, response) == 0)) {
                                             GSM_RST = 0;
                                             Delay_ms(10);
                                             GSM_RST = 1;
                                             time2Count = 40;
                                             TimerIntEn = 1;
                                             while(time < time2Count);
                                             TimerIntEn = 0;
                                             TimerIntFlg = 0;
                                             time2Count = 0;
                                             time = 0;
                                             failIndex = j;
                                             sentFail = 1;
                                 }
                                 
                                 UARTIntEn = 0;
                        }

                        clrbuff(&memset, gsm_gps_buff, '\0', 90);
                        clrbuff(&memset, nmea, '\0', 90);
                        clrbuff(&memset, latitude, '\0', 25);
                        clrbuff(&memset, longitude, '\0', 25);
                        clrbuff(&memset, tmp, '\0', 2);
                        clrbuff(&memset, temp, '\0', 40);

                        EEPROM_Write(0x01, crash);
                        Delay_ms(20);
                        for(i = 0x60; i = 0x80; i++){
                                EEPROM_Write(i, 0xFF);
                                Delay_ms(20);
                        }
                        EEPROM_Write(0x90, 0xFF);
                        Delay_ms(20);
                        EEPROM_Write(0x91, 0xFF);
                        Delay_ms(20);
                        EEPROM_Write(0x02, 0xFF);
                        Delay_ms(20);
                       
                        TMR1IE_bit = 1;
                       
                        crash = 0;
                   }
             }
     }
}

karthi06
Novice
 
Posts: 17
Joined: Mon Feb 24, 2014 8:47 pm

Re: No output after load program

Postby ober » Tue Mar 11, 2014 8:11 am

OK, this obviously is not a simple code :)

Also, I did not see any configuration bits setting in the code, is being set in the IDE window?

Please try with a very basic program to verify the board is working, a LED blinking program will do that nicely!

LED Blinking is "Hello World" for microcontroller system.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: No output after load program

Postby karthi06 » Tue Mar 11, 2014 6:35 pm

How about this coding,it a simple coding to display characters in lcd display,as shown below:

// LCD module connections
sbit LCD_RS at LATD0_bit;
sbit LCD_EN at LATD1_bit;
sbit LCD_D4 at LATD2_bit;
sbit LCD_D5 at LATD3_bit;
sbit LCD_D6 at LATD4_bit;
sbit LCD_D7 at LATD5_bit;

sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// End LCD module connections

void main() {

ANSELD = 0x00;
TRISD = 0x00;
PORTD = 0x00;

Delay_ms(100);

LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);

LCD_Out(1,1,"Accident");
LCD_Out(2,2,"Notifier");


while(1){

Delay_ms(2000);
LCD_Out(1,1,"Accident");
LCD_Out(2,2,"Notifier");
Delay_ms(2000);
LCD_Out(1,1,"Karthigan");
LCD_Out(2,2,"Dasaratha");

}
}
karthi06
Novice
 
Posts: 17
Joined: Mon Feb 24, 2014 8:47 pm

Re: No output after load program

Postby ober » Tue Mar 11, 2014 10:06 pm

Is simple enough if the hardware is working and the PIC is running correctly! I will still go to LED blinking, only after it works, we can further do other stuff.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Previous

Return to PIC Development Tool

Who is online

Users browsing this forum: No registered users and 2 guests

cron