View previous topic :: View next topic |
Author |
Message |
fletchersk8
Joined: 20 Sep 2011 Posts: 3
|
test program flashing led pic 18f4550 help!!! |
Posted: Tue Sep 20, 2011 6:44 pm |
|
|
Hello, this is my first topic, and I'm a newbie when it comes to programming pic 18f4550. My problem is that i started with the most basic program: the flashing led, provided by the pic wizard, but when i run it in my pic it doesn't work. The thing that drove me crazy is when i accidentally touched pin rb7: it started to work!! I reviewed all code and i didn't find any error and i desperately need to see what's going wrong, otherwise i won't be able to develop my senior project, please anyone help me!! this is my source code:
Code: |
#include <main.h>
#include <LCD.C>
void main()
{
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
lcd_init();
setup_oscillator(OSC_250KHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
//Example blinking LED program
while(true){
output_low(LED);
delay_ms(DELAY);
output_high(LED);
delay_ms(DELAY);
}
}
|
and the main.h code is:
Code: |
#include <18F4550.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL1 //No PLL PreScaler
#FUSES CPUDIV1 //No System Clock Postscaler
#FUSES INTXT //Internal Oscillator, XT used by USB
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(int=250000)
//#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#define LED PIN_A1
#define DELAY 1000
|
I'm using 4.120 version.
Thanks for your help |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
fletchersk8
Joined: 20 Sep 2011 Posts: 3
|
|
Posted: Tue Sep 20, 2011 8:26 pm |
|
|
Yes PCM, i already have a 10 k pull-up resistor at MCLR, but i need to run my device at 250 Khz due to an inconsistence between 24lc 256 and usb frequency. This eeprom runs up to 400 Khz. That's why i set the #fuses directives. May it be a bug or something?
The test program doesn´t have the dual oscillator option, so i have to modify it the way i did mine, so i guess: is the oscillator line with a bad configuration? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 20, 2011 8:46 pm |
|
|
The i2c bus speed for your eeprom is limited to 400 KHz.
You don't have to run the PIC at that speed. You can run the PIC at
48 MHz and still run the eeprom at 100 KHz or 400 KHz. There is no
requirement to match the PIC speed to the i2c bus speed. |
|
|
fletchersk8
Joined: 20 Sep 2011 Posts: 3
|
|
Posted: Tue Sep 20, 2011 8:55 pm |
|
|
PCM programmer wrote: | The i2c bus speed for your eeprom is limited to 400 KHz.
You don't have to run the PIC at that speed. You can run the PIC at
48 MHz and still run the eeprom at 100 KHz or 400 KHz. There is no
requirement to match the PIC speed to the i2c bus speed. |
there is a way i can achieve that (example program)?
i was working with a pic 16f887 and when it was running at 4mhz i didn´t get any response from the eeprom. the thing is that: how can i get my eeprom work at the desired frequency with my pic working on a superior frequency? inserting delays in the eeprom routine?
i can post the code if you want to |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 20, 2011 11:44 pm |
|
|
Quote: | inserting delays in the eeprom routine?
|
It's not needed. Don't worry about it. The CCS compiler automatically
adjusts the delays in the #use i2c() library code. You don't have to do it.
Here is a sample program which uses the CCS 25256.c eeprom driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=30346&start=10
Make sure that you have 4.7K pullup resistors on both SDA and SCL.
You can specify other pins than E2 and E0 for sda and scl. Edit the
program so it specifies the PIC pins that your board has connected to
SDA and SCL on the 24LC256. |
|
|
|