<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>S12 / MagniV MicrocontrollersのトピックMapping a structure to a port.</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150603#M4266</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style=": ; font-size: 2;"&gt;Hi to all.&lt;BR /&gt;I am porting some code from a PIC to a HCS12 micro. I want to use the&lt;BR /&gt;same lcd routines on the new micro. I seem to have it mostly figured out&lt;BR /&gt;but I,m not sure how to "map" the lcd structure onto the hcs12 port(Port AD I/O Register; address 0x00000270)&lt;BR /&gt;I'm fairly new to this sort of stuff and am a bit stuck.&lt;BR /&gt;&lt;BR /&gt;Ive tried this , but it does not work. It compiles but the outputs don't work.&lt;BR /&gt;My lack of "C" knowledge is letting me down here I think :0(&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="genmed"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: 2;"&gt;Code:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;struct lcd_pin_map&lt;BR /&gt;{&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char unused&amp;nbsp; &amp;nbsp;:1;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char enable&amp;nbsp; &amp;nbsp; :1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char rs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;:1;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// access to the LCD pins.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char rw&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; :1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char data&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;:4;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // The bits are allocated from&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;struct lcd_pin_map lcd;&lt;BR /&gt;&lt;BR /&gt;#define lcd_pin_map lcd @ (*((volatile unsigned char *)(REG_BASE + 0x00000270)))&lt;/P&gt;&lt;P&gt;I basically want to connect the lcd(16*2) to port AD.&lt;/P&gt;&lt;P&gt;If anyone has any other nice lcd routines I'm happy to try them out.&lt;BR /&gt;&lt;BR /&gt;Any help appreciated.&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Rob&lt;BR /&gt;&lt;/P&gt;&lt;SPAN class="postbody"&gt;&lt;/SPAN&gt;&lt;SPAN class="gensmall"&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Apr 2008 19:00:15 GMT</pubDate>
    <dc:creator>Seegoon</dc:creator>
    <dc:date>2008-04-25T19:00:15Z</dc:date>
    <item>
      <title>Mapping a structure to a port.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150603#M4266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style=": ; font-size: 2;"&gt;Hi to all.&lt;BR /&gt;I am porting some code from a PIC to a HCS12 micro. I want to use the&lt;BR /&gt;same lcd routines on the new micro. I seem to have it mostly figured out&lt;BR /&gt;but I,m not sure how to "map" the lcd structure onto the hcs12 port(Port AD I/O Register; address 0x00000270)&lt;BR /&gt;I'm fairly new to this sort of stuff and am a bit stuck.&lt;BR /&gt;&lt;BR /&gt;Ive tried this , but it does not work. It compiles but the outputs don't work.&lt;BR /&gt;My lack of "C" knowledge is letting me down here I think :0(&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="genmed"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: 2;"&gt;Code:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;struct lcd_pin_map&lt;BR /&gt;{&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char unused&amp;nbsp; &amp;nbsp;:1;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char enable&amp;nbsp; &amp;nbsp; :1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char rs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;:1;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// access to the LCD pins.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char rw&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; :1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char data&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;:4;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // The bits are allocated from&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;struct lcd_pin_map lcd;&lt;BR /&gt;&lt;BR /&gt;#define lcd_pin_map lcd @ (*((volatile unsigned char *)(REG_BASE + 0x00000270)))&lt;/P&gt;&lt;P&gt;I basically want to connect the lcd(16*2) to port AD.&lt;/P&gt;&lt;P&gt;If anyone has any other nice lcd routines I'm happy to try them out.&lt;BR /&gt;&lt;BR /&gt;Any help appreciated.&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Rob&lt;BR /&gt;&lt;/P&gt;&lt;SPAN class="postbody"&gt;&lt;/SPAN&gt;&lt;SPAN class="gensmall"&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 19:00:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150603#M4266</guid>
      <dc:creator>Seegoon</dc:creator>
      <dc:date>2008-04-25T19:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Mapping a structure to a port.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150604#M4267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello Rob,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Assuming you are using Code Warrior, most of the work of defining individual bits within each register has already been done, within the header file for the device you are using.&amp;nbsp; You could&amp;nbsp;create a similar bit field method for&amp;nbsp;a custom declaration, using the header file as a model.&amp;nbsp; But it is probably simpler to just add a few custom macros to re-define the&amp;nbsp;pin names, certainly for the individual pins used for LCD control.&amp;nbsp; For example -&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#define ENABLE&amp;nbsp; PT1AD0_PT1AD01&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#define&amp;nbsp;RS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PT1AD0_PT1AD02&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#define&amp;nbsp;RW&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PT1AD0_PT1AD03&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;DDR1AD0 = 0xFF;&amp;nbsp; /* Set port bits for output */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;RW = 0;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;RS = 0;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;ENABLE = 1;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For handling the data nybble, an alternative might possibly be a more complex macro -&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#define DATA_MASK 0xF0&amp;nbsp; /* Upper nybble */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#define LCD_DATA(data) PT1AD0 &amp;amp;= ~DATA_MASK; PT1AD0 |= ((data)&amp;lt;&amp;lt;4)&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;LCD_DATA('A'/16);&amp;nbsp; /* High nybble */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;LCD_DATA('A'%16);&amp;nbsp; /* Low nybble */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You do not mention which HCS12 device you are using.&amp;nbsp; Perhaps you should check the address of the port register you are using.&amp;nbsp; Some devices seem to use an address of 0x0271, rather than 0x0270.&amp;nbsp; Of course, this is not an issue if you make use of the CW header.&amp;nbsp; Additionally, did you set the port bits for output?&amp;nbsp; The DDR setting may be opposite to what the PIC uses.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-04-25&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;11:55 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 20:39:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150604#M4267</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-04-25T20:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Mapping a structure to a port.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150605#M4268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Some things to consider:&lt;BR /&gt;&lt;BR /&gt;The bitfield struct you have written is not ISO C and may not work on ISO C compilers. Only the int type is allowed for bitfields.&lt;BR /&gt;&lt;BR /&gt;Allocating two variables at the same location will never work out well. The register is already allocated at the location you want. You could simply copy the struct to and from that register location; there is no need to map anything.&lt;BR /&gt;&lt;BR /&gt;Since bitfields are poorly specified by the C standard, and therefore most likely non-portable (especially not between big- and little endian cpus), the best thing is to get rid of them entirely and use the bitwise operators and bit masks instead. The resulting machine code will be identical, but the C code will be portable.&lt;BR /&gt;&lt;BR /&gt;Also out of curiousity, which HCS12 derivate is that? I don't know of one that has an AD on address 270h. They usually don't support I/O from the A/D port either, just inputs.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 20:49:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150605#M4268</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2008-04-25T20:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Mapping a structure to a port.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150606#M4269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;For a comprehensive answer have a look at &lt;A href="http://www.freescale.com/files/microcontrollers/doc/app_note/AN2485.pdf" rel="nofollow" target="_blank"&gt;AN2485&lt;/A&gt; which details how we built some software stationery using this kind of approach. Depending on the part you are using you may find some stationery that fits.&lt;/DIV&gt;&lt;DIV&gt;Placing the structure at a place in memory is dependent on the compiler but something like this will probably work:&lt;/DIV&gt;&lt;DIV&gt;1/ Define a type&lt;/DIV&gt;&lt;DIV&gt;2/ Declare a variable of that type @address&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;typedef struct&lt;BR /&gt;{&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char unused&amp;nbsp; &amp;nbsp;:1;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char enable&amp;nbsp; &amp;nbsp; :1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char rs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;:1;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// access to the LCD pins.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char rw&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; :1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;char data&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;:4;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // The bits are allocated from&lt;BR /&gt;} tlcd_pin_map;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;volatile tlcd_pin_map @ (REG_BASE + 0x00000270);&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 21:19:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150606#M4269</guid>
      <dc:creator>Steve</dc:creator>
      <dc:date>2008-04-25T21:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: Mapping a structure to a port.</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150607#M4270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;hi there.&lt;/DIV&gt;&lt;DIV&gt;Thanks for the tips. I think I'll take your advice and change the way&lt;/DIV&gt;&lt;DIV&gt;these drivers work to make them more portable.&lt;/DIV&gt;&lt;DIV&gt;I'm using the mc9s12gc64. Here is a copy of the IO_Map.h (generated by processor expert)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have managed to get it working by commenting out the definition of __PTAD , otherwise I get conflicts.&lt;/DIV&gt;&lt;DIV&gt;The address very well may not be at 0x270 , depends on what REG_BASE is.&lt;/DIV&gt;&lt;DIV&gt;As I said , I got it working , but its not elegant :0(&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;/*** PTAD - Port AD I/O Register; 0x00000270 ***/typedef union {  byte Byte;  struct {    byte PTAD0       :1;                                       /* Port AD Bit 0 */    byte PTAD1       :1;                                       /* Port AD Bit 1 */    byte PTAD2       :1;                                       /* Port AD Bit 2 */    byte PTAD3       :1;                                       /* Port AD Bit 3 */    byte PTAD4       :1;                                       /* Port AD Bit 4 */    byte PTAD5       :1;                                       /* Port AD Bit 5 */    byte PTAD6       :1;                                       /* Port AD Bit 6 */    byte PTAD7       :1;                                       /* Port AD Bit 7 */  } Bits;} PTADSTR;extern volatile PTADSTR _PTAD @(REG_BASE + 0x00000270);&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:53:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Mapping-a-structure-to-a-port/m-p/150607#M4270</guid>
      <dc:creator>Seegoon</dc:creator>
      <dc:date>2020-10-29T08:53:23Z</dc:date>
    </item>
  </channel>
</rss>

