Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

How do I start with converting C++ lib


  • Please log in to reply
2 replies to this topic

#1 James Allen

James Allen

    New Member

  • Members
  • Pip
  • 1 posts

Posted 15 February 2011 - 09:21 PM

Hi

This is my first post in the forums and whilst being a C# dev for nearly 8 years, I've not done much with C or C++. I have recently purchased the DFRobots LCD 48x84 shield (http://goo.gl/BFlhd) and was trying to work out where to start converting the C to C#? I got a bit stumped with things like:

  TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
  TCCR2B &= ~(1<<WGM22);
  TCCR2B = (1<<CS22)|(1<<CS21);      
   
  ASSR |=(0<<AS2);
 
   // Use normal mode  
   TCCR2A =0;    
   //Timer2 Overflow Interrupt Enable  
   TIMSK2 |= (0<<OCIE2A);
   TCNT2=0x6;  // counting starts from 6;  
   TIMSK2 = (1<<TOIE2);    
  
  SREG|=1<<SREG_I;
And even more like that...
   // LCD_RST = 0;
   DDRD |= (1<<SPI_CS)|(1<<LCD_DC)|(1<<LCD_RST)|(1<<SPI_MOSI)|(1<<SPI_SCK)|(1<<LCD_BL);
  
   PORTD &= ~(1<<LCD_RST);
   delayMicroseconds(1);
   PORTD |= (1<<LCD_RST);  

   PORTD &= ~(1<<SPI_CS);
   delayMicroseconds(1);
   PORTD |= (1<<SPI_CS);  
   delayMicroseconds(1);

I searched to see if someone has already converted this (no sense reinventing the wheel) but couldn't find anything.

Does anyone have any pointers?

Thanks

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 15 February 2011 - 11:35 PM

You're looking at raw microcontroller C instructions here. Some of them will be easy to translate. Some of them you may need to write native code (ARM C/C++) drivers for--like has been done on Arduino. Some quick tips: 1. DDRD is a memory location on AVR chips which designates which "D pins" are input vs. output. It's a bitmask of all the "D pins". In .NET MF, you'll create InputPorts or OutputPorts for these (or TristatePorts if you need to switch back and forth between input and output on a particular pin). 2. PORTD is a memory location on AVR chips which tells each "D pin" whether to source current or sink current (+5V or 0V). 3. "D pins" means the pins that start with "D" in their name...on the microcontroller. Also, for a lot of these types of things...if you're using SPI, you'll want to just go ahead and use the buillt-in .NET Micro Framework SPI functions. Unless the SPI data lines used for the shield are "special pins"--in which case you'll need to bit-bang it. Finally, if you want microsecond delays...you can do that in .NET MF, but you'll need to use native code interop to guarantee that kind of precision. Chris

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 16 February 2011 - 07:11 AM

I have recently purchased the DFRobots LCD 48x84 shield (http://goo.gl/BFlhd) and was trying to work out where to start converting the C to C#? I searched to see if someone has already converted this (no sense reinventing the wheel) but couldn't find anything.

Please have a look at the following forum posts:

For future reference, the LCD has PCD8544 compatible controller and it is often found in Nokia 3310 and 5110 mobile phones.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.