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

Collecting different Pins to a new port-variable

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



Joined: 25 Jan 2010
Posts: 36

View user's profile Send private message

Collecting different Pins to a new port-variable
PostPosted: Mon Feb 01, 2010 9:52 am     Reply with quote

hello everyone

I have a question for software-design. I think in every mcu-system are not full ports used for peripherals.

I mean, I have PIN_G1, PIN_G3, PIN_G4, PIN_G5, PIN_D0, PIN_D7, PIN_F2 and I would have this to a port-name LCD which I can use for writing and reading like this:
Code:

bitset(Lcd_PORT,EN);
Lcd_PORT=((Lcd_PORT&0x0F)+(ctrl&0xF0));
delay_ms(1);
bitclr(Lcd_PORT,EN);
delay_ms(1);

Is there any CCS-feature possibility to do this, or how could I do this ?

Thank you for helping.
Best regards
P51D
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 01, 2010 12:59 pm     Reply with quote

I have done this, to make a port with different pins

Code:

    1
    2 // this is a virtual port when we dont have a single 8bit output port
    3
    4 #define VPORT_0 PIN_A1
    5 #define VPORT_1 PIN_A2
    6 #define VPORT_2 PIN_A3
    7 #define VPORT_3 PIN_A4
    8 #define VPORT_4 PIN_B0
    9 #define VPORT_5 PIN_B1
   10 #define VPORT_6 PIN_B2
   11 #define VPORT_7 PIN_B3
   12
   13
   14 void virtPortWrite(int d)
   15 {
   16    output_bit(VPORT_0,bit_test(d,0));
   17    output_bit(VPORT_1,bit_test(d,1));
   18    output_bit(VPORT_2,bit_test(d,2));
   19    output_bit(VPORT_3,bit_test(d,3));
   20    output_bit(VPORT_4,bit_test(d,4));
   21    output_bit(VPORT_5,bit_test(d,5));
   22    output_bit(VPORT_6,bit_test(d,6));
   23    output_bit(VPORT_7,bit_test(d,7));
   24 }
   25
   

_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 01, 2010 1:01 pm     Reply with quote

The easiest way is to use the Flex driver(s) in the Code Library forum.
P51D



Joined: 25 Jan 2010
Posts: 36

View user's profile Send private message

PostPosted: Mon Feb 01, 2010 2:35 pm     Reply with quote

Sorry but which driver do you mean. I don't know the flex drivers.

once more, thank you for helping
best regards
P51D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 01, 2010 2:38 pm     Reply with quote

Code Library forum:
http://www.ccsinfo.com/forum/viewforum.php?f=2
P51D



Joined: 25 Jan 2010
Posts: 36

View user's profile Send private message

PostPosted: Tue Feb 02, 2010 7:22 am     Reply with quote

There are the pins in a struct for creating a new virtual port.

I tested the driver for a 20x4 lcd and there are some problems:
If I set other ports to output the writing on the lcd are not at the maximum of brightness.
And when I write "This is the 1st line" I can only read "Tisisste1 ine".
all connections are correct and there is also a capacitance at the supply of the lcd.

Is this a software problem?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 02, 2010 9:56 am     Reply with quote

Are you using the 20x4 Flex driver ?

1. Post your (small) test program that calls the Flex driver functions.
It must be compilable with no errors.

2. Post the manufacturer and part number of your LCD.

3. Post the version number of your CCS compiler.
P51D



Joined: 25 Jan 2010
Posts: 36

View user's profile Send private message

PostPosted: Tue Feb 02, 2010 11:51 am     Reply with quote

I use this driver
http://www.ccsinfo.com/forum/viewtopic.php?t=28268


Code:

set_tris_g(0xF000);                    // LCD Output
lcd_init();                                  // LCD initialisieren
delay_ms(5);
printf(lcd_putc, "\fABCDEFGHIJKLMNOPQRST");
delay_ms(3000);

in the header I have changed this settings:
Code:

#define LCD_DB4   PIN_G6
#define LCD_DB5   PIN_G7
#define LCD_DB6   PIN_G8
#define LCD_DB7   PIN_G9

#define LCD_RS    PIN_G0
#define LCD_RW    PIN_G1
#define LCD_E     PIN_G2

and also all "delay_cycle" and "delay_us" I've changed in "delay_ms(1)" minimal. because the speed was to fast and then there were lost some datas.
yet I have the right information on the display but the writing ist still not bright. I think there is a problem with the control-pins RS, RW, E.

I don't know the exactli manufacturer and part number of the lcd but I know the lcd driver on it: HD44780 (I think this is a standart lcd)

the version number of the pcwhd compiler is 4.057

thank you for helping
best regards
P51D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 02, 2010 1:19 pm     Reply with quote

Post a compilable test program. It must have:

1. The #include line for the PIC's .h file.
2. The #fuses statement(s).
3. The #use delay() statement.
4. #define statements.
5. The #include line for the LCD driver file.
6. A main().
7. The code in main().
P51D



Joined: 25 Jan 2010
Posts: 36

View user's profile Send private message

PostPosted: Tue Feb 02, 2010 2:50 pm     Reply with quote

The main with the fuses
Code:

//*****************************************************************************
// Externe Dateien einbinden
#include <30F6012A.h>
#include "lcd.h"

//*****************************************************************************
// Präprozessoren
#device *=16
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PR                       //Promiary Oscillator
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES WPSB1                    //Watch Dog Timer PreScalar B 1:1
#FUSES WPSA1                    //Watch Dog Timer PreScalar A 1:1
#FUSES PUT64                    //Power On Reset Timer value 64ms
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES LPOL_HIGH                //Low-Side Transistors Polarity is Active-High (PWM 0,2,4 and 6)
   //PWM module low side output pins have active high output polar
#FUSES HPOL_HIGH                //High-Side Transistors Polarity is Active-High (PWM 1,3,5 and 7)
   //PWM module high side output pins have active high output polarity
#FUSES NOPWMPIN                 //PWM outputs drive active state upon Reset
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOCOE                    //Device will reset into operational mode
#FUSES ICS0                     //ICD communication channel 0
#FUSES RESERVED                 //Used to set the reserved FUSE bits
#FUSES RESERVED                 //Used to set the reserved FUSE bits

#use delay(clock=20000000)

//*****************************************************************************
// Funktionen
void SysInit(void){   
   set_tris_g(0xF000);                       // LCD Output
   
   lcd_init();                                  // LCD initialisieren
   printf(lcd_putc, "\fABCDEFGHIJKLMNOPQRST");
   delay_ms(3000);
}
//*****************************************************************************
// Hauptfunktion
void main(){
   SysInit();

   // Test the clear screen and newline commands.
   // Also test that we can write to all 4 lines.
   printf(lcd_putc, "\fThis is the 1st line");
   printf(lcd_putc, "\nNext is the 2nd line");
   printf(lcd_putc, "\nThis is the 3rd line");
   printf(lcd_putc, "\nFinally the 4th line");
   delay_ms(3000);

   for(;;){
   }
}

and the defines in the lcd.h (I didn't insert the whole driver code)
Code:

// These pins are for my Microchip PicDem2-Plus board,
// which I used to test this driver.
// An external 20x4 LCD is connected to these pins.
// Change these pins to match your own board's connections.

#define LCD_DB4   PIN_G6
#define LCD_DB5   PIN_G7
#define LCD_DB6   PIN_G8
#define LCD_DB7   PIN_G9

#define LCD_RS    PIN_G0
#define LCD_RW    PIN_G1
#define LCD_E     PIN_G2

Sorry, but I thought that you didn't want all parts. My mistake.

best regards
P51D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 02, 2010 2:53 pm     Reply with quote

Quote:

#include <30F6012A.h>
#include "lcd.h"

The 20x4 Flex LCD driver was only tested with the PCM and PCH compilers.
I don't have the PCD compiler, so I can't test your code.
P51D



Joined: 25 Jan 2010
Posts: 36

View user's profile Send private message

PostPosted: Wed Feb 03, 2010 1:32 am     Reply with quote

ok,
I think there is a problem with a control pin, because on a reset the writing is bright, then the lcd is updating and the brightness of the writing is not enough.

I will look this with an oszi and then I will check the delay-times.

you will hear from me.

best regards
P51D
P51D



Joined: 25 Jan 2010
Posts: 36

View user's profile Send private message

PostPosted: Thu Feb 04, 2010 6:58 am     Reply with quote

hi

I've checked the pins. the problem was the speed:
Code:

void lcd_send_nibble(int8 nibble){
   // Note:  !! converts an integer expression
   // to a boolean (1 or 0).
   
   output_bit(LCD_DB4, !!(nibble & 1));
   output_bit(LCD_DB5, !!(nibble & 2));
   output_bit(LCD_DB6, !!(nibble & 4));   
   output_bit(LCD_DB7, !!(nibble & 8));   
   
   delay_us(15);
   output_high(LCD_E);
   delay_us(15);
   output_low(LCD_E);
}

the cycle-delay and the delay_us(2) are both changed to delay_us(15)
then the hd44780 lcd driver.

best regards
P51D
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