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 CCS Technical Support

BUG in CCS???? (3.126)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








BUG in CCS???? (3.126)
PostPosted: Thu Feb 10, 2005 6:34 pm     Reply with quote

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







PostPosted: Fri Feb 11, 2005 3:07 am     Reply with quote

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








PostPosted: Fri Feb 11, 2005 6:01 am     Reply with quote

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

View user's profile Send private message MSN Messenger

PostPosted: Fri Feb 11, 2005 6:34 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 11, 2005 7:03 am     Reply with quote

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








PostPosted: Fri Feb 11, 2005 8:35 am     Reply with quote

i try with this fuses and disabling adc, and i have the same problem Sad, 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

View user's profile Send private message

PostPosted: Fri Feb 11, 2005 8:39 am     Reply with quote

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








PostPosted: Fri Feb 11, 2005 9:00 am     Reply with quote

yes, 3.216, a lapsus Rolling Eyes Wink
Ttelmah
Guest







PostPosted: Fri Feb 11, 2005 9:19 am     Reply with quote

Anonymous wrote:
yes, 3.216, a lapsus Rolling Eyes Wink

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








PostPosted: Fri Feb 11, 2005 11:12 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 11, 2005 11:39 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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