CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Burned chip 16f877A with QL200
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
loginatnine
Guest







Burned chip 16f877A with QL200
PostPosted: Mon Oct 06, 2008 10:16 pm     Reply with quote

Hi
I'm very new at programming PIC so I bought a QL200 off ebay so I could try and program some simple things in order to get better. I have a 128x64LCD with a preprogrammed hex file to use it that came with the package. I modified the program so I could use it with CCS as it was compiled with HITECH. Problem is, so far, I burned two chips while programming the 16f877a with this program and I'm wondering if I'm missing something here. The programming software I use gives me a fuse error at the end of the programming and after I can't erase/program the chip anymore. But, the chip still displays what it's supposed to on the lcd if I turn the board on.
So here is my code, is there something wrong with it?
Billion thanks

Code:
/*Librairie LCD 128x64*/
#include <16F877A.h>   
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

void lcd_init(void);
void lcd_clear(void);                     //clear screen   
void lcd_flash(void);    //blink
void lcd_print(char*);
void send_d(int x);       //send data
void send_i(int x);       //send command.
void chk_busy(void);
void delay(void);                     
void delay1(void);

int busy;

void lcd_init(void)
{
   SET_TRIS_A(0x00); //Put the IO A and D as outputs
   SET_TRIS_D(0x00);
   #USE STANDARD_IO (A)
     output_low(PIN_A0);                         //reset LCD
     delay();                       
     output_high(PIN_A0);
     ;       
     output_high(PIN_A2);                         //8 bit as parallel.
     send_i(0x30);                  //basic operation instruction
   send_i(0x01);                  //display off 
   send_i(0x06);                  //set the cursor's moving direction.
   send_i(0x0c);                  //on display,off cursor,off blink
}

void lcd_clear(void)
{
  send_i(0x1);                   //clear all
  send_i(0x34);                  //extend.
  send_i(0x30);                  //basic
}

void lcd_flash(void)
{
  send_i(0x08);                  //off display.
  delay1();                      //delay
  send_i(0x0c);                  //on display
  delay1();
  delay1();                      //delay
  send_i(0x08);                  //off
  delay1();
  send_i(0x0c);                  //on
  delay1();
  delay1();
  send_i(0x08);                  //off
  delay1();
  send_i(0x0c);                  //on
  delay1();
  delay1();
}

void lcd_print(char *string)
{
  int i=0;                         //define loop count.
  while(string[i]!= 0)
     {
        send_d(string[i]);             //
        delay();                 //
        i++;                    //get next.
     }
}

//--------------------------------------------
//send data
void send_d(int x)
{
   chk_busy();                  //check busy.
   output_high(PIN_A5);                       
   output_low(PIN_A4);                           
   OUTPUT_D(x);                     //data to bus.       
   output_high(PIN_A3);
   ;
   ;
   ;                         //enable.                                 
   output_low(PIN_A3);                         //disable.
}

//--------------------------------------------
//send command.
void send_i(int x)
{
   chk_busy();                   //check lcd if busy.
   output_low(PIN_A5);                         
   output_low(PIN_A4);                         
   OUTPUT_D(x);                      //data to bus.       
   output_high(PIN_A3);
   ;
   ;
   ;                          //enable.           
   output_low(PIN_A3);                         //disable.
}

//-------------------------------------------
//check lcd busy.
void chk_busy()

   busy=1;                      //set busy signal                   
   SET_TRIS_D(0xFF);                  //change the bus to input.         
   output_low(PIN_A5);                                   
   output_high(PIN_A4);                                         
   while(busy)                 
      {
         ;
         ;
         ;
         output_high(PIN_A3);
         ;
         ;
         ;                   //enable.
         if(!input(PIN_D7))
            {
               busy=0;
           }        
        ;
        ;
        ;   
         output_low(PIN_A3);                   //DISABLE.
      }
   output_low(PIN_A3);                         //DISABLE.
   SET_TRIS_D(0x00);                   //bus as output.
 }

//-------------------------------------------
//delay
void delay()
{
    int i=0;
    while(i<50)
       {
       i++;
       }
}

//-------------------------------------------
//delay1
void delay1()
{
    int i;
    for(i=0;i<10;i++)
      {
        delay();               //call delay.
      }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 06, 2008 10:25 pm     Reply with quote

Start with a simple test program. See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=36062
loginatnine
Guest







PostPosted: Mon Oct 06, 2008 10:31 pm     Reply with quote

thanks for your quick reply
Unfortunately, I don't have another 16f877a to try the simple program but I already tried a program with the library I just posted and it worked like 10 times and after it burned the chip...

I put 20MHz as the clock thinking this was the processor speed, could that be the problem? Or could it be the different fuses I used in my code?

Thanks again
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 06, 2008 10:37 pm     Reply with quote

Read the link posts at the link that I posted above.
One of the comments in it is:
Quote:

The photograph of the board shows a 4 MHz crystal. You need to look
at your board, to what crystal it really has.


Set the #use delay() value to the same as the crystal frequency.
Use the XT fuse for 4 MHz, and the HS fuse for 20 Mhz.
Guest








PostPosted: Mon Oct 06, 2008 10:49 pm     Reply with quote

PCM programmer wrote:
Read the link posts at the link that I posted above.
One of the comments in it is:
Quote:

The photograph of the board shows a 4 MHz crystal. You need to look
at your board, to what crystal it really has.


Set the #use delay() value to the same as the crystal frequency.


I read the thread and that is why I was wondering if the delay=20000000 could be a problem....I think the board has a 4MHz crystal.
Quote:
Use the XT fuse for 4 MHz, and the HS fuse for 20 Mhz.

How can I do that? Do I need to put two #use delay()?
thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 06, 2008 10:53 pm     Reply with quote

No. Look at the sample program in the link that I posted and
do it just like that.

Run the sample program instead of your program.
Guest








PostPosted: Mon Oct 06, 2008 10:58 pm     Reply with quote

PCM programmer wrote:
No. Look at the sample program in the link that I posted and
do it just like that.

Run the sample program instead of your program.


Ok I'll try that as soon as I can get a new chip since this one seems dead....
thanks for your help, much appreciated!
loginatnine
Guest







PostPosted: Tue Oct 07, 2008 7:00 pm     Reply with quote

PCM programmer wrote:
No. Look at the sample program in the link that I posted and
do it just like that.

Run the sample program instead of your program.


I've tried the sample program and it worked great. I've narrowed the problem I think, it's a #fuse problem. When I use the code posted earlier, the fuses are probably not right and it's making my chip not programmable afterward. But I've found a way to force erase the chip and I can program it again. And when I'm using the supplied example codes, I have no problem displaying stuff on the lcd and erase/program the chip as many times I want.
In the example source file, it's using this command :
__CONFIG(0x1832); //__CONFIG_DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_ON&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OS

I've not found all those fuses in the 16f877a.h file so I'm kinda lost with which one to use...
Thanks for your help
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 07, 2008 7:45 pm     Reply with quote

The fuses are given at the top of the 16F877A.h file:
Code:
// Fuses:
LP, XT, HS, RC, NOWDT, WDT, NOPUT, PUT, PROTECT, DEBUG, NODEBUG
NOPROTECT, NOBROWNOUT, BROWNOUT, LVP, NOLVP, CPD, NOCPD,
WRT_50%, NOWRT, WRT_5%, WRT_25%

You can translate them by inspection. For example, this fuse:
Code:
_DEBUG_OFF

pretty obviously translates to:
Code:
NODEBUG


Some other examples of how to translate them:
Code:
_BODEN_OFF = NOBROWNOUT

_PWRTE_ON = PUT


Your fuses have Code Protection enabled, and Flash Write Enable set to 50%. I question the need for any of that.
loginatnine



Joined: 07 Oct 2008
Posts: 8

View user's profile Send private message

PostPosted: Wed Oct 08, 2008 6:57 am     Reply with quote

PCM programmer wrote:
The fuses are given at the top of the 16F877A.h file:
Code:
// Fuses:
LP, XT, HS, RC, NOWDT, WDT, NOPUT, PUT, PROTECT, DEBUG, NODEBUG
NOPROTECT, NOBROWNOUT, BROWNOUT, LVP, NOLVP, CPD, NOCPD,
WRT_50%, NOWRT, WRT_5%, WRT_25%

You can translate them by inspection. For example, this fuse:
Code:
_DEBUG_OFF

pretty obviously translates to:
Code:
NODEBUG


Some other examples of how to translate them:
Code:
_BODEN_OFF = NOBROWNOUT

_PWRTE_ON = PUT


Your fuses have Code Protection enabled, and Flash Write Enable set to 50%. I question the need for any of that.


Thanks for your help PCM

I've figured it out a little more, the problem comes from the 4MHz crystal because I have no problem when I remove the crystal when programming/erasing and putting it back afterward. Here is what the "tech support" of the ql200 said (his english is very poor):

because your hex file will RB7 pull-down for "0", can't for "1", so program error,
1. remove Y3(or J9,J10),
2. will “SUPPLY” Switch set for “OFF”
3. again will “SUPPLY” Switch set for “ON”
4. Then “Erase”/ ”Program”,

So I believe there is something wrong in my code that is making the rb7 unable to pull-up? FYI, Y3 = 4MHz crystal and J9-J10 = the jumpers that control the crystal

Do you have any idea what he meant and how I could correct it?

Thanks again
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 08, 2008 12:59 pm     Reply with quote

I think he is saying this:

The built-in programmer on the QL200 board can not work properly if
the PIC is already programmed to set Pin B7 to a low output level.
He gives instructions for a "work around" method to fix the problem.

- He wants you to temporarily remove the crystal (or the jumpers for the
crystal).
- Turn off the power to the board, and then turn it on.
- Program or erase the PIC.
- Turn off the power, re-install the crystal, and turn on the power.

When you follow this procedure, the existing program will not run
because there is no crystal installed. Therefore, pin B7 will not be low.
It will be set as a "floating" input. So the QL200 programmer can now
work properly.

I have a vague memory of some programmer having this same problem,
but I don't remember the details. I think they solved it by putting a
delay at the beginning of the program (100 ms or more). But I don't
know anything about the QL200 board. I think you should follow his
instructions.
loginatnine



Joined: 07 Oct 2008
Posts: 8

View user's profile Send private message

PostPosted: Wed Oct 08, 2008 6:39 pm     Reply with quote

PCM programmer wrote:
I think he is saying this:

The built-in programmer on the QL200 board can not work properly if
the PIC is already programmed to set Pin B7 to a low output level.
He gives instructions for a "work around" method to fix the problem.

- He wants you to temporarily remove the crystal (or the jumpers for the
crystal).
- Turn off the power to the board, and then turn it on.
- Program or erase the PIC.
- Turn off the power, re-install the crystal, and turn on the power.

When you follow this procedure, the existing program will not run
because there is no crystal installed. Therefore, pin B7 will not be low.
It will be set as a "floating" input. So the QL200 programmer can now
work properly.

I have a vague memory of some programmer having this same problem,
but I don't remember the details. I think they solved it by putting a
delay at the beginning of the program (100 ms or more). But I don't
know anything about the QL200 board. I think you should follow his
instructions.


it may sound stupid and forgive me if it is, but couldn't I just program the B7 to be at high level? I'm not using this output I'm only using I/O-A and I/O-D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 08, 2008 6:44 pm     Reply with quote

Or don't use pins B6 and B7. Leave them as inputs (which is the
condition they are in, after power-on reset). Let the QL200 programmer
be the only thing that uses those pins.
loginatnine



Joined: 07 Oct 2008
Posts: 8

View user's profile Send private message

PostPosted: Wed Oct 08, 2008 6:59 pm     Reply with quote

PCM programmer wrote:
Or don't use pins B6 and B7. Leave them as inputs (which is the
condition they are in, after power-on reset). Let the QL200 programmer
be the only thing that uses those pins.

The thing is, as you can see in my code, I never use B6-B7 or set them as ouputs...And I've tried to set the Bx I/O as inputs and I got the same "Fuses" error at the end of programming....I'm lost a lil bit, if you have an idea it'd be great but I know how it can be hard debugging on a forum Rolling Eyes

Thanks for your help pcm
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 08, 2008 7:02 pm     Reply with quote

I noticed that. I wondered why the support guy told you about pin B7.
I assumed that you showed him some different code.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group