|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
BUG in CCS???? (3.126) |
Posted: Thu Feb 10, 2005 6:34 pm |
|
|
try to observe results of this simple code:
Code: |
#include <18F2520.h>
#use delay(clock=4000000)
#include <lcd20x4.h>
#fuses XT, NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOPBADEN
void main()
{
int tecla;
lcd_init();
while(1){
tecla = input(PIN_B1);
if(tecla==0)
{
lcd_putc("\f");
lcd_putc("actived");
}
else
{
lcd_putc("\f");
lcd_putc("desactived");
}
}
}
|
If execute this code into a pic, LCD shows EVER actived, and the push button its not active of course, the same as PIN_B2 ... i dont know if occure with B3, but im sure that with PIN_B0 this not a problem, the same as PIN_C7, etc...
i think there is a problem with portb... at least PB1,PB2 ....
Saludos desde España |
|
|
Ttelmah Guest
|
|
Posted: Fri Feb 11, 2005 3:07 am |
|
|
How is B1 wired?.
What you have posted, works fine for me. _provided_ you have an external 'pull up' resistor, or activate the internal ones.
Remember something has to make the pin go 'high'.
Best Wishes |
|
|
Guest
|
|
Posted: Fri Feb 11, 2005 6:01 am |
|
|
my pins b0, b1, and b2, are active with low level, puts a '0' into the pic when i presses it.
pull ups has been actived, but i dont put in the final 'bug' code, its very stranger cause b0 works OK .... |
|
|
T0ni0
Joined: 21 Jan 2005 Posts: 11
|
|
Posted: Fri Feb 11, 2005 6:34 am |
|
|
This PIC needs to make a config word for Digital I/O PortB, i think it is your problem.
For initialize PORTB Microchip says:
CLRF PORTB ; Initialize PORTB by
; clearing output
; data latches
CLRF LATB ; Alternate method
; to clear output
; data latches
MOVLW 0Fh ; Set RB<4:0> as
MOVWF ADCON1 ; digital I/O pins
; (required if config bit
; PBADEN is set)
MOVLW 0CFh ; Value used to
; initialize data
; direction
MOVWF TRISB ; Set RB<3:0> as inputs
; RB<5:4> as outputs
; RB<7:6> as inputs
Can you try this fuse?
#fuses NOWDT,WDT128,XT, NOPROTECT, BROWNOUT, BORV25, NOPUT, NOCPD, NOSTVREN, DEBUG, NOLVP, NOWRT, NOWRTD, NOIESO, NOFCMEN, NOPBADEN, NOWRTC, NOWRTB, NOEBTR, NOEBTRB, NOCPB, NOLPT1OSC, MCLR, NOXINST
;*************************************
Pues eso que por defecto en este PIC el puertoB es entradas analógicas como sucede en el portA, pero en este caso se define en la palabra de configuración
;*************************************
Cu |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Feb 11, 2005 7:03 am |
|
|
TOniO is right, portB is very likely mixed with the A/D-convert pins.
from the manual: Quote: | The PBADEN bit in Configuration
Register 3H configures PORTB pins to
reset as analog or digital pins by controlling
how the PCFG0 bits in ADCON1 are
reset. |
So either add '#fuse NOPBADEN' to make portB power up as digital I/O-pins or instead of the assembly code provided by TOniO you can use:
Code: | main()
{
setup_adc( ADC_OFF );
set_adc_channel(NO_ANALOGS);
...
} |
|
|
|
Guest
|
|
Posted: Fri Feb 11, 2005 8:35 am |
|
|
i try with this fuses and disabling adc, and i have the same problem , if i change switches to PC7, and PC6, its works greath... :S i continue thinkin about a bug in this version of CCS, cause PB0 doesnt have this problen, only PB1, PB2...
thanks for urs replies! |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Feb 11, 2005 8:39 am |
|
|
I'm not sure which version you are using. In the top of this thread you mention 3.126 which is a very, very old version. Or is this an error and did you mean 3.216? |
|
|
Guest
|
|
Posted: Fri Feb 11, 2005 9:00 am |
|
|
yes, 3.216, a lapsus |
|
|
Ttelmah Guest
|
|
Posted: Fri Feb 11, 2005 9:19 am |
|
|
Anonymous wrote: | yes, 3.216, a lapsus |
Have you got access to a simulator?. I'd check whether the ADC configuration register is being setup correctly. I must admit, that I gave up a while ago, on this and another of the 'modern' chips, and my own 'initialisation' code for the latter chips, always writes the registers directly, since I was finding odd parts of the initialisation were 'wrong'. I'd suspct this is what is happening in your case... :-(
Best Wishes |
|
|
Guest
|
|
Posted: Fri Feb 11, 2005 11:12 am |
|
|
in proteus seems to work ok, but...... at least i resolve put all this:
#fuses NOWDT,WDT128,XT, NOPROTECT, BROWNOUT, BORV25, NOPUT, NOCPD
#fuses NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOIESO, NOFCMEN, NOPBADEN
#fuses NOWRTC, NOWRTB, NOEBTR, NOEBTRB, NOCPB, NOLPT1OSC, MCLR, NOXINST
port_b_pullups(true);
set_tris_b(0x07);
setup_adc_ports(NO_ANALOGS);
thanks all! ;) |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Feb 11, 2005 11:39 am |
|
|
I had a look at the CCS generated startup code: Code: | .................... #include <18F2520.h>
.................... //////// Standard Header file for the PIC18F2520 device ////////////////
.................... #device PIC18F2520
.................... #list
....................
.................... #use delay(clock=4000000)
.................... //#include <lcd20x4.h>
....................
.................... #fuses XT, NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOPBADEN
....................
.................... void main()
.................... {
0004: CLRF FF8
0006: BCF FD0.7
0008: CLRF FEA
000A: CLRF FE9
000C: MOVF adcon1,W
000E: ANDLW C0
0010: IORLW 03 <-- bug, this equals AN0_TO_AN11
0012: MOVWF adcon1
0014: MOVLW 07
0016: MOVWF cmcon
0018: MOVF cmcon,W
001A: BCF pir2.6
.................... int tecla;
| This explains why your I/O-ports are not working, they are configured as analog ports. So, no matter how you configure the PBADEN fuse, most ports are configured as analog inputs.
V3.218 has this fixed and configures all ports as digital I/O-pins. |
|
|
|
|
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
|