View previous topic :: View next topic |
Author |
Message |
Quick_Silver
Joined: 04 Jul 2005 Posts: 4
|
16F628 to 16F88 |
Posted: Mon Jul 04, 2005 3:12 pm |
|
|
Want to switch from a PIC16F628 to a PIC16F88. They say its pin compatible put when I compile the program that ran on the 628 an programme it onto the 88, nothing want's to work like its suppose to. I did use the fuses right and I included the 16F88.h and removed the 16F628.h header file. I have an LCD connected to port B like usaul,but its not functioning right. I have tested it on the 628, and it still works. I wrote a basic blink led programme and it works, except on B6 PIN 12.Y?. I also have buttons connected to A0-A3 and neither want to work. I have disabled the ADC but the pins wont function as inputs. What am I doing wrong? I use IC-Progv v1.5D, and a JDM programmer device and PIC C. I also tried setting the analogue pins to std io pins,but this also doesn't want to work.And still PIN 12 B6 does nothing.
Any help would be appreciated. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Mon Jul 04, 2005 10:02 pm |
|
|
Just a quick thought....
The 16F88 has built-in comparators, right? I'm pretty sure that they default to on. Have you disabled them? |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Mon Jul 04, 2005 10:19 pm |
|
|
Pin compatible in Microchip speak means electrically compatible, it does not mean register compatible. Some work required.... _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
theMagni
Joined: 21 May 2004 Posts: 48 Location: Victoria, BC
|
|
Posted: Tue Jul 05, 2005 10:53 am |
|
|
newguy wrote: | Just a quick thought....
The 16F88 has built-in comparators, right? I'm pretty sure that they default to on. Have you disabled them? |
They default to off. This is NOT accomplished by writing 0x00 to the CMCON register (0x9C), but by leaving it alone (or writing 0bXXXXX111 ). Refer to the datasheet, section 13. (p.123 of the PDF.)
Might I add: If you can possibly use the 16F87, use that instead of the 16F88 just to make sure that the comparators aren't messing with you. (Or that you're not messing with them.)
If he's got the wrong registers, then he might be writing to the CMCON register by mistake. _________________ In the 90's, I promised myself I'd never use a so-called "smiley icon". I hate what I've become. ;) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 05, 2005 11:29 am |
|
|
Quote: | I wrote a basic blink led programme and it works, except on B6 PIN 12. |
1. Post your blink program.
2. Post your version of the compiler.
3. Are you using a debugger that uses pin B6 (such as the ICD2) ? |
|
|
Quick_Silver
Joined: 04 Jul 2005 Posts: 4
|
My blink program for 16f628 and 16f88 |
Posted: Tue Jul 05, 2005 12:38 pm |
|
|
The 16F628 program works fine. I know there are different ways to do what I'm doing but this is just a basic program to test if all the pins that i need works. Im using (or trying to) the 16F88 because it has just enouhg memory and rom for my application.
I use CCS v.3.170, a JDM programmer and ICprog 1.5D that supports the 16F88(apparently).
1.16F628 blink program.
#include <16F628.h>
#device *=16
#use delay(clock=4000000)
#fuses HS,NOPROTECT,NOWDT,NOPUT,BROWNOUT,MCLR,NOLVP,NOCPD
int btn = 0;
char press = false;
void button()
{
if(!input(PIN_A0))
{
delay_ms(10);
while(!input(PIN_A0)){}
press = true;
btn = 1;
}
if(!input(PIN_A1))
{
delay_ms(10);
while(!input(PIN_A1)){}
press = true;
btn = 2;
}
if(!input(PIN_A2))
{
delay_ms(10);
while(!input(PIN_A2)){}
press = true;
btn = 3;
}
if(!input(PIN_A3))
{
delay_ms(10);
while(!input(PIN_A3)){}
press = true;
btn = 4;
}
}
void blink_led()
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
output_high(PIN_B4);
output_high(PIN_B5);
output_high(PIN_B6);
output_high(PIN_B7);
delay_ms(250);
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_B4);
output_low(PIN_B5);
output_low(PIN_B6);
output_low(PIN_B7);
delay_ms(250);
}
void main()
{
SETUP_CCP1(CCP_OFF);
setup_counters(RTCC_INTERNAL,WDT_18MS);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while(1)
{
while(press == false)
{
button();
}
press = false;
if(btn == 1 || btn == 2 || btn == 3 || btn == 4)
{
blink_led();
blink_led();
}
}
}
2. 16F88 blink program
The setting and registers that are marked out are all the setting that I've tried so far and none works.
#include <16F88.h>
#device *=16
#device adc=8
#use delay(clock=4000000)
#fuses HS,NOPROTECT,NOWDT,NOPUT,BROWNOUT,MCLR,NOLVP,NOCPD
//#byte OSCCON = 0x8F
//#byte CMCON = 0x9C
//#byte CVRCON = 0x9D
//#use standard_io(A)
//#use standard_io(B)
int btn = 0;
char press = false;
void button()
{
if(!input(PIN_A0))
{
delay_ms(10);
while(!input(PIN_A0)){}
press = true;
btn = 1;
}
if(!input(PIN_A1))
{
delay_ms(10);
while(!input(PIN_A1)){}
press = true;
btn = 2;
}
if(!input(PIN_A2))
{
delay_ms(10);
while(!input(PIN_A2)){}
press = true;
btn = 3;
}
if(!input(PIN_A3))
{
delay_ms(10);
while(!input(PIN_A3)){}
press = true;
btn = 4;
}
}
void blink_led()
{
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
output_high(PIN_B4);
output_high(PIN_B5);
output_high(PIN_B6); //This PIN does not work for some reason
output_high(PIN_B7); //but all the others does
delay_ms(250);
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_B4);
output_low(PIN_B5);
output_low(PIN_B6);
output_low(PIN_B7);
delay_ms(250);
}
void main()
{
setup_adc(ADC_OFF);
setup_adc(NO_ANALOGS);
SETUP_CCP1(CCP_OFF);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,WDT_18MS);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//CMCON = 7; // I've tried these but they wont fix my problem
//CVRCON = 0;
//#use fast_io(a)
//set_tris_a(0b11111111);
//set_tris_b(0b00000000);
while(1)
{
while(press == false)
{
button(); //None off my buttons on these PINs works.
}
press = false;
if(btn == 1 || btn == 2 || btn == 3 || btn == 4)
{
blink_led();
blink_led();
}
}
}
If someone can please test this program and tell me what I am doing wrong I would appreciate it alot. Both these programmes compiled,but as we all know that says nothing at all.
Thanx guys.
I think my next problem is going to be the LCD that's in my original program which I actually want to run on this PIC. So if anyone gest an LCD 16x2 line running on port B, the usual setting for the LCD.h file I'd like to see that as well.
Thanx again. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 05, 2005 12:49 pm |
|
|
I'll look at problem, but while you're waiting, I just want to say that
that's not a simple test program. Not even close. |
|
|
Quick_Silver
Joined: 04 Jul 2005 Posts: 4
|
|
Posted: Tue Jul 05, 2005 1:18 pm |
|
|
Hi, me again, I don't use a debugger on B6. Can I disable this function. If I've got it right, its the NODEBUG fuse. I tried it and B6 still wont function correctly.
A short explanation of my basic blink program :
1. The button procedure just checks if a button is pressed and then sets the btn variable to the corresponding value.
2. The if() cheks to see if any of the buttons was pressed, meaning if it works that A0-A4 works correctly.
3. A led will then blink on each pin of port B.
Thats it.
Thanx. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 05, 2005 2:19 pm |
|
|
In your version of the compiler (3.170), the following functions don't
work properly for the 16F88:
setup_comparator()
setup_adc_ports()
There may be other functions that also don't work.
Also, the start-up code inserted by the compiler is wrong.
It doesn't configure the A/D pins as all digital. It doesn't
turn off the comparators. It turns on the A/D.
To fix this, you need to configure the ANSEL and CMCON
registers with code, as shown below. Also you need to
turn off the ADC with the setup_adc() function.
I tested the following program with PCM vs. 3.170 with
a 16F88, and it does blink pin B6 (pin 12 on the 16F88 chip).
If this program doesn't work for you, then make sure you
disconnect your JDM programmer from your board.
Code: | #include <16F88.h>
#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
// Define the register addresses for ANSEL and CMCON.
#byte ANSEL = 0x9B
#byte CMCON = 0x9C
void main()
{
ANSEL = 0; // Set all A/D pins to digital
CMCON = 7; // Disable comparators
setup_adc(ADC_OFF);
while(1)
{
output_high(PIN_B6);
delay_ms(500);
output_low(PIN_B6);
delay_ms(500);
}
} |
|
|
|
Quick_Silver
Joined: 04 Jul 2005 Posts: 4
|
|
Posted: Tue Jul 05, 2005 2:38 pm |
|
|
Thanks,I'll check it out and let you know if it works. Do you think that my LCD will work normal now? , because B6 pin12 was one of the data pins.
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 05, 2005 2:52 pm |
|
|
I don't know. Just try it. |
|
|
Quick_Silver
Joined: 04 Jul 2005 Posts: 4
|
|
Posted: Wed Jul 06, 2005 2:10 pm |
|
|
Hi,thanks, it worked. Everything works like it should know.
I confirm that the settings above worked sweet.
Thanks alot.
|
|
|
|