Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

Archive for January, 2010

PIC18F4520 :: Pyramid Animation [Part 3]

Posted by Circuit Negma on January 20, 2010


Created By: Hussein Nosair

#include GenericTypeDefs.h”

Code Snippet
  1. /*********************************************************************
  2. *
  3. *                  Generic Type Definitions
  4. *
  5. *********************************************************************
  6. * FileName:        GenericTypeDefs.h
  7. * Dependencies:    None
  8. * Processor:       PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32
  9. ********************************************************************/
  10.  
  11. #ifndef __GENERIC_TYPE_DEFS_H_
  12. #define __GENERIC_TYPE_DEFS_H_
  13.  
  14. typedef enum _BOOL { FALSE = 0, TRUE } BOOL;    // Undefined size
  15.  
  16. #ifndef NULL
  17. #define NULL    0//((void *)0)
  18. #endif
  19.  
  20. #define    PUBLIC                                  // Function attributes
  21. #define PROTECTED
  22. #define PRIVATE   static
  23.  
  24. typedef unsigned char        BYTE;                // 8-bit unsigned
  25. typedef unsigned short int    WORD;                // 16-bit unsigned
  26. typedef unsigned long        DWORD;                // 32-bit unsigned
  27. typedef unsigned long long    QWORD;                // 64-bit unsigned
  28. typedef signed char            CHAR;                // 8-bit signed
  29. typedef signed short int    SHORT;                // 16-bit signed
  30. typedef signed long            LONG;                // 32-bit signed
  31. typedef signed long long    LONGLONG;            // 64-bit signed
  32.  
  33. /* Alternate definitions */
  34.                 typedef voidVOID;
  35.  
  36.                 typedef charCHAR8;
  37.        typedef unsigned charUCHAR8;
  38.  
  39. /* Processor & Compiler independent, size specific definitions */
  40. // To Do:  We need to verify the sizes on each compiler.  These
  41. //         may be compiler specific, we should either move them
  42. //         to "compiler.h" or #ifdef them for compiler type.
  43.           typedef signed intINT;
  44.          typedef signed charINT8;
  45.     typedef signed short intINT16;
  46.      typedef signed long intINT32;
  47.     typedef signed long longINT64;
  48.  
  49.         typedef unsigned intUINT;
  50.        typedef unsigned charUINT8;
  51.   typedef unsigned short intUINT16;
  52.    typedef unsigned long intUINT32;  // other name for 32-bit integer
  53.   typedef unsigned long longUINT64;
  54.  
  55. typedef union _BYTE_VAL
  56. {
  57.     BYTE Val;
  58.     struct
  59.     {
  60.         unsigned char b0:1;
  61.         unsigned char b1:1;
  62.         unsigned char b2:1;
  63.         unsigned char b3:1;
  64.         unsigned char b4:1;
  65.         unsigned char b5:1;
  66.         unsigned char b6:1;
  67.         unsigned char b7:1;
  68.     } bits;
  69. } BYTE_VAL, BYTE_BITS;
  70.  
  71. typedef union _WORD_VAL
  72. {
  73.     WORD Val;
  74.     BYTE v[2];
  75.     struct
  76.     {
  77.         BYTE LB;
  78.         BYTE HB;
  79.     } byte;
  80.     struct
  81.     {
  82.         unsigned char b0:1;
  83.         unsigned char b1:1;
  84.         unsigned char b2:1;
  85.         unsigned char b3:1;
  86.         unsigned char b4:1;
  87.         unsigned char b5:1;
  88.         unsigned char b6:1;
  89.         unsigned char b7:1;
  90.         unsigned char b8:1;
  91.         unsigned char b9:1;
  92.         unsigned char b10:1;
  93.         unsigned char b11:1;
  94.         unsigned char b12:1;
  95.         unsigned char b13:1;
  96.         unsigned char b14:1;
  97.         unsigned char b15:1;
  98.     } bits;
  99. } WORD_VAL, WORD_BITS;
  100.  
  101. typedef union _DWORD_VAL
  102. {
  103.     DWORD Val;
  104.     WORD w[2];
  105.     BYTE v[4];
  106.     struct
  107.     {
  108.         WORD LW;
  109.         WORD HW;
  110.     } word;
  111.     struct
  112.     {
  113.         BYTE LB;
  114.         BYTE HB;
  115.         BYTE UB;
  116.         BYTE MB;
  117.     } byte;
  118.     struct
  119.     {
  120.         WORD_VAL low;
  121.         WORD_VAL high;
  122.     }wordUnion;
  123.     struct
  124.     {
  125.         unsigned char b0:1;
  126.         unsigned char b1:1;
  127.         unsigned char b2:1;
  128.         unsigned char b3:1;
  129.         unsigned char b4:1;
  130.         unsigned char b5:1;
  131.         unsigned char b6:1;
  132.         unsigned char b7:1;
  133.         unsigned char b8:1;
  134.         unsigned char b9:1;
  135.         unsigned char b10:1;
  136.         unsigned char b11:1;
  137.         unsigned char b12:1;
  138.         unsigned char b13:1;
  139.         unsigned char b14:1;
  140.         unsigned char b15:1;
  141.         unsigned char b16:1;
  142.         unsigned char b17:1;
  143.         unsigned char b18:1;
  144.         unsigned char b19:1;
  145.         unsigned char b20:1;
  146.         unsigned char b21:1;
  147.         unsigned char b22:1;
  148.         unsigned char b23:1;
  149.         unsigned char b24:1;
  150.         unsigned char b25:1;
  151.         unsigned char b26:1;
  152.         unsigned char b27:1;
  153.         unsigned char b28:1;
  154.         unsigned char b29:1;
  155.         unsigned char b30:1;
  156.         unsigned char b31:1;
  157.     } bits;
  158. } DWORD_VAL;
  159.  
  160. #define LSB(a)          ((a).v[0])
  161. #define MSB(a)          ((a).v[1])
  162.  
  163. #define LOWER_LSB(a)    ((a).v[0])
  164. #define LOWER_MSB(a)    ((a).v[1])
  165. #define UPPER_LSB(a)    ((a).v[2])
  166. #define UPPER_MSB(a)    ((a).v[3])
  167.  
  168. typedef union _QWORD_VAL
  169. {
  170.     QWORD Val;
  171.     DWORD d[2];
  172.     WORD w[4];
  173.     BYTE v[8];
  174.     struct
  175.     {
  176.         DWORD LD;
  177.         DWORD HD;
  178.     } dword;
  179.     struct
  180.     {
  181.         WORD LW;
  182.         WORD HW;
  183.         WORD UW;
  184.         WORD MW;
  185.     } word;
  186.     struct
  187.     {
  188.         unsigned char b0:1;
  189.         unsigned char b1:1;
  190.         unsigned char b2:1;
  191.         unsigned char b3:1;
  192.         unsigned char b4:1;
  193.         unsigned char b5:1;
  194.         unsigned char b6:1;
  195.         unsigned char b7:1;
  196.         unsigned char b8:1;
  197.         unsigned char b9:1;
  198.         unsigned char b10:1;
  199.         unsigned char b11:1;
  200.         unsigned char b12:1;
  201.         unsigned char b13:1;
  202.         unsigned char b14:1;
  203.         unsigned char b15:1;
  204.         unsigned char b16:1;
  205.         unsigned char b17:1;
  206.         unsigned char b18:1;
  207.         unsigned char b19:1;
  208.         unsigned char b20:1;
  209.         unsigned char b21:1;
  210.         unsigned char b22:1;
  211.         unsigned char b23:1;
  212.         unsigned char b24:1;
  213.         unsigned char b25:1;
  214.         unsigned char b26:1;
  215.         unsigned char b27:1;
  216.         unsigned char b28:1;
  217.         unsigned char b29:1;
  218.         unsigned char b30:1;
  219.         unsigned char b31:1;
  220.         unsigned char b32:1;
  221.         unsigned char b33:1;
  222.         unsigned char b34:1;
  223.         unsigned char b35:1;
  224.         unsigned char b36:1;
  225.         unsigned char b37:1;
  226.         unsigned char b38:1;
  227.         unsigned char b39:1;
  228.         unsigned char b40:1;
  229.         unsigned char b41:1;
  230.         unsigned char b42:1;
  231.         unsigned char b43:1;
  232.         unsigned char b44:1;
  233.         unsigned char b45:1;
  234.         unsigned char b46:1;
  235.         unsigned char b47:1;
  236.         unsigned char b48:1;
  237.         unsigned char b49:1;
  238.         unsigned char b50:1;
  239.         unsigned char b51:1;
  240.         unsigned char b52:1;
  241.         unsigned char b53:1;
  242.         unsigned char b54:1;
  243.         unsigned char b55:1;
  244.         unsigned char b56:1;
  245.         unsigned char b57:1;
  246.         unsigned char b58:1;
  247.         unsigned char b59:1;
  248.         unsigned char b60:1;
  249.         unsigned char b61:1;
  250.         unsigned char b62:1;
  251.         unsigned char b63:1;
  252.     } bits;
  253. } QWORD_VAL;
  254.  
  255. #endif //__GENERIC_TYPE_DEFS_H_

#include “LCD.h”

Unfortunately, I cannot show this library as it does not belong to me. However, I am using RD4, RD5, RD6, and RD7 for data lines between LCD hardware module and PIC uC.

You could modify and use the LCDBlocking.h and LCDBlocking.c files included with Microchip TCPIP stack.

Moving on next to defining the pyramid custom characters. The pyramid consist of 8 custom characters, defined with an 8×8 array.

   1: const unsigned char p2[8][8] = {{0,0,0,0,0,0,0,0x1F},

   2:                                  {0,0,0,0,0,0,0x1F,0x1F},

   3:                                  {0,0,0,0,0,0x1F,0x1F,0x1F},

   4:                                  {0,0,0,0,0x1F,0x1F,0x1F,0x1F},

   5:                                  {0,0,0,0x1F,0x1F,0x1F,0x1F,0x1F},

   6:                                  {0,0,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F},

   7:                                  {0,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F},

   8:                                  {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}};

 

Once the characters are defined in the code, we need to load those characters into the LCD CGRAM. To do this the following code was used to upload those characters onto the LCD.

   1: /************* LOAD PYRAMID INTO LCD uC ****************/

   2: for(i=0; i<8; i++)

   3: {

   4:     LCDCustomChar(i, p2[i]);

   5: }

   6:  

   7: i = 0;

   8: j = 1;

   9: LED_IO = 0;

  10: LCD_Move(2,2);

  11:     

 

And next, we need the algorithm that will execute the pyramid and perform the animation.

   1: while(1)                                    // Loop infinitly

   2: {

   3:     if (!TMR1Delay)

   4:     {

   5:         //LED_IO ^= 1;

   6:         

   7:         if (i<8)

   8:         {

   9:             LCDReadCustomChar(i++);

  10:         }

  11:         else if(i<17)

  12:         {                

  13:             LCDReadCustomChar(16-i);

  14:             i++;

  15:         }

  16:         else

  17:         {

  18:             LCDErase();

  19:             if(j > 4)

  20:             {

  21:                 j = 1;

  22:             }    

  23:             LCD_Move(j++,2);        

  24:             i = 0;

  25:         }

  26:         

  27:         TMR1Delay = TMR1_DELAY;

  28:     }

  29: }

Here is the complete code of test.c file

 

   1: /***********************************************************************/

   2: /*                      PoE Keypad Test Program                        */

   3: /*                                                                     */

   4: /*  Created By: Hussein Nosair                                         */

   5: /*  Date      : 01/27/2009                                             */

   6: /*  Project   : PoE_kp_testing                                         */

   7: /*  Proj. Path: C:\codes\PoE_kp_testing                                */

   8: /*  File Name : test.c                                                 */

   9: /*                                                                     */

  10: /* Author               Date      Comment                              */

  11: /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

  12: /* Hussein Nosair        1/14/09      test.c created                       */

  13: /* Hussein Nosair       1/07/09   test.c Fixed configurations bits     */

  14: /* Hussein Nosair       1/27/09   test.c Fixed bug in main program     */

  15: /***********************************************************************/

  16:  

  17: /***********************************************************************/

  18: /*                      DEFINE THE MOTHER CODE                         */

  19: /***********************************************************************/

  20: #define THIS_IS_STACK_APPLICATION               // Define this file to be the main Proj.'s File

  21:  

  22: /***********************************************************************/

  23: /*                      DEFINE THE LIBRARIES                           */

  24: /***********************************************************************/

  25: #include "Compiler.h"                           // Compiler configuration library

  26: #include "HardwareProfile.h"                    // Hardware configuration library

  27: #include "GenericTypeDefs.h"                    // Global definition library

  28: #include "LCD.h"                                // LCD library

  29:  

  30: /***********************************************************************/

  31: /*                     DEFINE STATIC VARIABLES                         */

  32: /***********************************************************************/

  33: #define TIMER1_LED_DELAY        2               // LED Timeout = 2*1.67sec

  34: #define TMR1_DELAY                5

  35:  

  36: /***********************************************************************/

  37: /*                     DEFINE GLOBAL VARIABLES                         */

  38: /***********************************************************************/

  39: unsigned char LEDTime;                          // Define LED timout

  40: unsigned char TMR1Delay;

  41:  

  42: const unsigned char p2[8][8] = {{0,0,0,0,0,0,0,0x1F},

  43:                                  {0,0,0,0,0,0,0x1F,0x1F},

  44:                                  {0,0,0,0,0,0x1F,0x1F,0x1F},

  45:                                  {0,0,0,0,0x1F,0x1F,0x1F,0x1F},

  46:                                  {0,0,0,0x1F,0x1F,0x1F,0x1F,0x1F},

  47:                                  {0,0,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F},

  48:                                  {0,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F},

  49:                                  {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}};

  50:  

  51: /***********************************************************************/

  52: /*                     DEFINE PRIVATE SUBROUTINES                      */

  53: /***********************************************************************/

  54: void InitializeBoard(void);                     // Define Board's hardware initialization subroutine

  55:  

  56: /***********************************************************************/

  57: /*                     PIC18 Interrupt Service Routines                */

  58: /***********************************************************************/

  59:     #pragma interruptlow LowISR

  60:     void LowISR(void)

  61:     {

  62:            if (PIR1bits.TMR1IF)

  63:         {

  64:             if(TMR1Delay)

  65:             {

  66:                 TMR1Delay--;

  67:             }    

  68:                         

  69:             PIR1bits.TMR1IF = 0;

  70:             TMR1H = 0x00;

  71:             TMR1L = 0x00;

  72:         }        

  73:  

  74:     }

  75:     

  76:     #pragma interruptlow HighISR

  77:     void HighISR(void){}

  78:     #pragma code lowVector=0x18

  79:     void LowVector(void){_asm goto LowISR _endasm}

  80:     #pragma code highVector=0x8

  81:     void HighVector(void){_asm goto HighISR _endasm}

  82:     #pragma code // Return to default code section

  83:  

  84: /***********************************************************************/

  85: /*                     MAIN PROGRAM ROUTINE                            */

  86: /***********************************************************************/

  87: void main(void)

  88: { 

  89:     unsigned char i;

  90:     unsigned char j;

  91:           

  92:             /************** INITIALIZE THE BOARD ************/

  93:             InitializeBoard();                  // Initialize board and PIC hardware

  94:  

  95:             /************** PREPARE THE LCD ****************/

  96:             LCDErase();                         // Clear the LCD

  97:             LCDHome();

  98:  

  99:             /************* LOAD PYRAMID INTO LCD uC ****************/

 100:             for(i=0; i<8; i++)

 101:             {

 102:                 LCDCustomChar(i, p2[i]);

 103:             }

 104:  

 105:             i = 0;

 106:             j = 1;

 107:             LED_IO = 0;

 108:             LCD_Move(2,2);

 109:     

 110:     

 111:     /********************** MAIN PROGRAM INFINITE LOOP *******************/

 112:     while(1)                                    // Loop infinitly

 113:     {

 114:         if (!TMR1Delay)

 115:         {

 116:             //LED_IO ^= 1;

 117:             

 118:             if (i<8)

 119:             {

 120:                 LCDReadCustomChar(i++);

 121:             }

 122:             else if(i<17)

 123:             {                

 124:                 LCDReadCustomChar(16-i);

 125:                 i++;

 126:             }

 127:             else

 128:             {

 129:                 LCDErase();

 130:                 if(j > 4)

 131:                 {

 132:                     j = 1;

 133:                 }    

 134:                 LCD_Move(j++,2);        

 135:                 i = 0;

 136:             }

 137:             

 138:             TMR1Delay = TMR1_DELAY;

 139:         }

 140:     }       

 141: }

 142:  

 143: /********************************************************************

 144: *       Function Name:  InitializeBoard                             *

 145: *       Return Value:   None                                        *

 146: *       Parameters:     void                                        *

 147: *       Description:    This routine initialize the on board's      *

 148: *                       modules and microprocessor.                 *

 149: ********************************************************************/

 150: void InitializeBoard(void)

 151: {

 152:     RCON    = 0x80;

 153:     INTCON  = 0xE0;

 154:     INTCON2 = 0x84;

 155:     INTCON3 = 0x00;

 156:  

 157:     // Digital Pins

 158:     ADCON1 = 0x0F;              // Analog pins to digital

 159:     CMCON = 0x00; //0xCF;

 160:     CVRCON = 0x00;

 161:  

 162:     // Enable internal PORTB pull-ups

 163:     INTCON2bits.RBPU = 1;

 164:     

 165:     //Enable Interrupts

 166:     //----------------------

 167:     RCONbits.IPEN = 1;            // Enable interrupt priorities

 168:     INTCONbits.GIEH = 1;

 169:     INTCONbits.GIEL = 1;

 170:     

 171:     // Timer 1 = 52.428msec

 172:     //------------------------

 173:     PIR1bits.TMR1IF = 0;

 174:     PIE1bits.TMR1IE = 1;

 175:     IPR1bits.TMR1IP = 0;

 176:     T1CON = 0xB1;

 177:     TMR1H = 0x00;

 178:     TMR1L = 0x00;

 179:     TMR1Delay = TMR1_DELAY;

 180:     

 181:     // Oscillator selection

 182:     //------------------------

 183:     OSCTUNE = 0x00;             //<-----------

 184:     

 185:     

 186:     //LEDs

 187:     //------------------------

 188:     LED_TRIS = 0;

 189:     LED_IO = 0;

 190:  

 191:     

 192:     // LCD

 193:     //------------------------

 194:     LCD_DATA_TRIS = 0x0F;   // Set Data Bus Direction to output

 195:     LCD_RD_WR_TRIS  = 0;    // Set R/W pin direction to output

 196:     LCD_RS_TRIS     = 0;    // Set Reset pin direction to output

 197:     LCD_E_TRIS      = 0;    // Set Enable pin direction to output

 198:     DelayMs(50);            // wait for 15ms to allow the voltage to  rise to moe than 4.5V

 199:     ClrWdt();    

 200:  

 201:      

 202:     // Initialize LCD

 203:     LCDInit();    

 204: }

Posted in C Programming, Electronics, Microchip PIC | Leave a Comment »

PIC18F4520 :: Pyramid Animation [Part 2]

Posted by Circuit Negma on January 20, 2010


Created By: Hussein Nosair

Project:

We are going to start with the main program. The main program is contained inside test.c file.

The following line 4 instruct the compiler to use test.c file as the main file of the project.

Code Snippet
  1. /***********************************************************************/
  2. /*                      DEFINE THE MOTHER CODE                         */
  3. /***********************************************************************/
  4. #define THIS_IS_STACK_APPLICATION               // Define this file to be the main Proj.'s File

The reason for this is because I am storing my project inside Microchip TCPIP stack folder to utilize the built in libraries such as LCD and RS 232 libraries.

Next we are going to include the necessary libraries to this project and define global variables limited to the scope of test.c file only.

   1: /***********************************************************************/

   2: /*                      DEFINE THE LIBRARIES                           */

   3: /***********************************************************************/

   4: #include "Compiler.h"                           // Compiler configuration library

   5: #include "HardwareProfile.h"                    // Hardware configuration library

   6: #include "GenericTypeDefs.h"                    // Global definition library

   7: #include "LCD.h"                                // LCD library

   8:  

   9: /***********************************************************************/

  10: /*                     DEFINE STATIC VARIABLES                         */

  11: /***********************************************************************/

  12: #define TIMER1_LED_DELAY        2               // LED Timeout = 2*1.67sec

  13: #define TMR1_DELAY                5

  14:  

  15: /***********************************************************************/

  16: /*                     DEFINE GLOBAL VARIABLES                         */

  17: /***********************************************************************/

  18: unsigned char LEDTime;                          // Define LED timout

  19: unsigned char TMR1Delay;

 

Include “Compiler.h”

   1: /*********************************************************************

   2:  *

   3:  *                  Compiler and hardware specific definitions

   4:  *

   5:  *********************************************************************

   6:  * FileName:        Compiler.h

   7:  * Dependencies:    None

   8:  ********************************************************************/

   9: #ifndef __COMPILER_H

  10: #define __COMPILER_H

  11:  

  12: // Include proper device header file

  13: #if defined(__18CXX) || defined(HI_TECH_C)    

  14:     // All PIC18 processors

  15:     #if defined(HI_TECH_C)    // HI TECH PICC-18 compiler

  16:         #define __18CXX

  17:         #include <htc.h>

  18:     #else                    // Microchip C18 compiler

  19:         #include <p18cxxx.h>

  20:     #endif

  21: #elif defined(__PIC24F__)    // Microchip C30 compiler

  22:     // PIC24F processor

  23:     #include <p24Fxxxx.h>

  24: #elif defined(__PIC24H__)    // Microchip C30 compiler

  25:     // PIC24H processor

  26:     #include <p24Hxxxx.h>

  27: #elif defined(__dsPIC33F__)    // Microchip C30 compiler

  28:     // dsPIC33F processor

  29:     #include <p33Fxxxx.h>

  30: #elif defined(__dsPIC30F__)    // Microchip C30 compiler

  31:     // dsPIC30F processor

  32:     #include <p30fxxxx.h>

  33: #elif defined(__PIC32MX__)    // Microchip C32 compiler

  34:     #if !defined(__C32__)

  35:         #define __C32__

  36:     #endif

  37:     #include <p32xxxx.h>

  38:     #include <plib.h>

  39: #else

  40:     #error Unknown processor or compiler.  See Compiler.h

  41: #endif

  42:  

  43: #include <stdio.h>

  44: #include <stdlib.h>

  45: #include <string.h>

  46:  

  47:  

  48: // Base RAM and ROM pointer types for given architecture

  49: #if defined(__C32__)

  50:     #define PTR_BASE        DWORD

  51:     #define ROM_PTR_BASE    DWORD

  52: #elif defined(__C30__)

  53:     #define PTR_BASE        WORD

  54:     #define ROM_PTR_BASE    WORD

  55: #elif defined(__18CXX)

  56:     #define PTR_BASE        WORD

  57:     #define ROM_PTR_BASE    unsigned short long

  58: #endif

  59:  

  60:  

  61: // Definitions that apply to all compilers, except C18

  62: #if !defined(__18CXX) || defined(HI_TECH_C)

  63:     #define memcmppgm2ram(a,b,c)    memcmp(a,b,c)

  64:     #define strcmppgm2ram(a,b)        strcmp(a,b)

  65:     #define memcpypgm2ram(a,b,c)    memcpy(a,b,c)

  66:     #define strcpypgm2ram(a,b)        strcpy(a,b)

  67:     #define strncpypgm2ram(a,b,c)    strncpy(a,b,c)

  68:     #define strstrrampgm(a,b)        strstr(a,b)

  69:     #define    strlenpgm(a)            strlen(a)

  70:     #define strchrpgm(a,b)            strchr(a,b)

  71:     #define strcatpgm2ram(a,b)        strcat(a,b)

  72: #endif

  73:  

  74:  

  75: // Definitions that apply to all 8-bit products

  76: // (PIC18)

  77: #if defined(__18CXX)

  78:     #define    __attribute__(a)

  79:  

  80:     #define FAR                         far

  81:  

  82:     // Microchip C18 specific defines

  83:     #if !defined(HI_TECH_C)

  84:         #define ROM                     rom

  85:         #define strcpypgm2ram(a, b)        strcpypgm2ram(a,(far rom char*)b)

  86:     #endif

  87:     

  88:     // HI TECH PICC-18 STD specific defines

  89:     #if defined(HI_TECH_C)

  90:         #define ROM                     const

  91:         #define rom

  92:         #define Nop()                   asm("NOP");

  93:         #define ClrWdt()                asm("CLRWDT");

  94:         #define Reset()                    asm("RESET");

  95:     #endif

  96:     

  97: // Definitions that apply to all 16-bit and 32-bit products

  98: // (PIC24F, PIC24H, dsPIC30F, dsPIC33F, and PIC32)

  99: #else

 100:     #define    ROM                        const

 101:  

 102:     // 16-bit specific defines (PIC24F, PIC24H, dsPIC30F, dsPIC33F)

 103:     #if defined(__C30__)

 104:         #define Reset()                asm("reset")

 105:         #define FAR                 __attribute__((far))

 106:     #endif

 107:  

 108:     // 32-bit specific defines (PIC32)

 109:     #if defined(__C32__)

 110:         #define persistent

 111:         #define far

 112:         #define FAR

 113:         #define Reset()                SoftReset()

 114:         #define ClrWdt()            (WDTCONSET = _WDTCON_WDTCLR_MASK)

 115:         #define Nop()                asm("nop")

 116:     #endif

 117: #endif

 118:  

 119:  

 120:  

 121: #endif

 

#include “HardwareProfile.h”

   1: /*********************************************************************

   2:  *

   3:  *    Hardware specific definitions

   4:  *

   5:  *********************************************************************

   6:  * FileName:        HardwareProfile.h

   7:  * Dependencies:    None

   8:  ********************************************************************/

   9: #ifndef __HARDWARE_PROFILE_H

  10: #define __HARDWARE_PROFILE_H

  11:  

  12: #include "Compiler.h"

  13:  

  14:  

  15: // Choose which hardware profile to compile for here.  See 

  16: // the hardware profiles below for meaning of various options.  

  17: #define PICDEMNET2

  18: //#define YOUR_BOARD

  19:  

  20: // If no hardware profiles are defined, assume that we are using 

  21: // a Microchip demo board and try to auto-select the correct profile

  22: // based on processor selected in MPLAB

  23: #if !defined(PICDEMNET2) && !defined(HPC_EXPLORER) && !defined(PICDEMZ) && !defined(EXPLORER_16) && !defined(PIC24FJ64GA004_PIM) && !defined(DSPICDEM11) && !defined(PICDEMNET2) && !defined(INTERNET_RADIO) && !defined(YOUR_BOARD)

  24:     #if defined(__18F97J60) || defined(_18F97J60) || defined(__18F4520)

  25:         #define PICDEMNET2

  26:     #endif

  27: #endif

  28:  

  29: // Set configuration fuses (but only once)

  30: #if defined(THIS_IS_STACK_APPLICATION)

  31:     #if defined(__18CXX)

  32:         #if defined(__EXTENDED18__)

  33:             #pragma config XINST=ON

  34:         #elif !defined(HI_TECH_C)

  35:             #pragma config XINST=OFF

  36:         #endif

  37:     

  38:         #if defined(__18F97J60) || defined(__18F96J65) || defined(__18F96J60) || defined(__18F87J60) || defined(__18F86J65) || defined(__18F86J60) || defined(__18F67J60) || defined(__18F66J65) || defined(__18F66J60) 

  39:             // PICDEM.net 2 or any other PIC18F97J60 family device

  40:             #pragma config WDT=OFF, FOSC2=ON, FOSC=HSPLL, ETHLED=OFF

  41:         #elif defined(__18F4520) || defined(__18F452)    

  42:             // STANLY KEYPAD

  43:             #pragma config OSC = HSPLL, FCMEN = ON, IESO = ON

  44:             #pragma config PWRT = ON, BOREN = ON, BORV = 1

  45:             #pragma config WDT = OFF, WDTPS = 2048

  46:             #pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = OFF, CCP2MX = PORTC

  47:             #pragma config STVREN = ON, LVP = OFF

  48:         #endif

  49:     #endif

  50: #endif // Prevent more than one set of config fuse definitions

  51:  

  52: // Clock frequency value.

  53: // This value is used to calculate Tick Counter value

  54: #if defined(__18CXX)

  55:     // All PIC18 processors

  56:     #if defined(PICDEMNET2) || defined(INTERNET_RADIO)

  57:         #define GetSystemClock()        (40000000ul) //(41666667ul)      // Hz

  58:         #define GetInstructionClock()    (GetSystemClock()/4)

  59:         #define GetPeripheralClock()    GetInstructionClock()

  60:     #else

  61:         #define GetSystemClock()        (40000000ul)      // Hz

  62:         #define GetInstructionClock()    (GetSystemClock()/4)

  63:         #define GetPeripheralClock()    GetInstructionClock()

  64:     #endif

  65: #endif

  66:  

  67: // Hardware mappings

  68: #if defined(PICDEMNET2) && !defined(HI_TECH_C)

  69: // PICDEM.net 2 (PIC18F97J60 + ENC28J60)   

  70:         

  71:     //Define Backlit keys, Speaker and RS-485 ports

  72:     #define LED_IO      LATCbits.LATC1              // Define RC1 to be LED port   

  73:     #define LED_TRIS    TRISCbits.TRISC1

  74:     

  75:     // LCD I/O pins

  76:     #define LCD_DATA_TRIS        (TRISD)

  77:     #define LCD_DATA_IO            (LATD)

  78:  

  79:     #define LCD_RD_WR_TRIS        (TRISEbits.TRISE2)

  80:     #define LCD_RD_WR_IO        (LATEbits.LATE2)

  81:     #define LCD_RS_TRIS            (TRISEbits.TRISE0)

  82:     #define LCD_RS_IO            (LATEbits.LATE0)

  83:     #define LCD_E_TRIS            (TRISEbits.TRISE1)

  84:     #define LCD_E_IO            (LATEbits.LATE1)

  85:  

  86: #elif defined(YOUR_BOARD)

  87: // Define your own board hardware profile here

  88:  

  89: #else

  90:     #error "Hardware profile not defined.  See available profiles in HardwareProfile.h.  Add the appropriate macro definition to your application configuration file ('TCPIPConfig.h', etc.)"

  91: #endif

  92:  

  93:  

  94: #if defined(__18CXX)    // PIC18

  95:     // UART mapping functions for consistent API names across 8-bit and 16 or 

  96:     // 32 bit compilers.  For simplicity, everything will use "UART" instead 

  97:     // of USART/EUSART/etc.

  98:     #define BusyUART()                BusyUSART()

  99:     #define CloseUART()                CloseUSART()

 100:     #define ConfigIntUART(a)        ConfigIntUSART(a)

 101:     #define DataRdyUART()            DataRdyUSART()

 102:     #define OpenUART(a,b,c)            OpenUSART(a,b,c)

 103:     #define ReadUART()                ReadUSART()

 104:     #define WriteUART(a)            WriteUSART(a)

 105:     #define getsUART(a,b,c)            getsUSART(b,a)

 106:     #define putsUART(a)                putsUSART(a)

 107:     #define getcUART()                ReadUSART()

 108:     #define putcUART(a)                WriteUSART(a)

 109:     #define putrsUART(a)            putrsUSART((far rom char*)a)

 110:  

 111: #endif

 112:  

 113:  

 114: #endif

Posted in C Programming, Electronics, Microchip PIC | Leave a Comment »

PIC18F4520 :: Pyramid Animation [Part 1]

Posted by Circuit Negma on January 15, 2010


Created By: Hussein Nosair

The following is an animation of a costumed characters that make up the shape of pyramid.

Custom characters array:

   1: const unsigned char p2[8][8] = {{0,0,0,0,0,0,0,0x1F},

   2:                                  {0,0,0,0,0,0,0x1F,0x1F},

   3:                                  {0,0,0,0,0,0x1F,0x1F,0x1F},

   4:                                  {0,0,0,0,0x1F,0x1F,0x1F,0x1F},

   5:                                  {0,0,0,0x1F,0x1F,0x1F,0x1F,0x1F},

   6:                                  {0,0,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F},

   7:                                  {0,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F},

   8:                                  {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}};

Final Result of Pyramid:

Project Description:

This project will attempt to accomplish the following:

1. Utilize the LCD abilities of creating Custom Characters to build a customized Pyramid.

2. Create a code that will animate the custom characters

3. Move the animation across all 4 lines of the 20×4 LCD module.

Hardware:

1. uC : PIC18F4520 @ Microchip

2. External Clock (Oscillator) : 10MHz

3. Internal Clock (Oscillator) : 40MHz

4. LCD : 20×4 HDM20416L-1-YA0S

Software:

1. Editor IDE : MPLAB IDE v8.40

2. Compiler : MPLAB C18 v3.34

3. Internal clock is set to 4xPLL = 4×10MHz = 40MHz

Posted in C Programming, Electronics, Microchip PIC | Leave a Comment »

Surface Mount Packages :: 3-pins Devices

Posted by Circuit Negma on January 15, 2010


Created By: Hussein Nosair

I am trying to convert a PCB from through hole components to surface mount. However, since I have limited resources to aid me in soldering surface mount device. I need to find the largest possible surface mount package for a 3-pins devices.

Since I do not have a copy of the EIA standards, I decided to use alternative method in gathering information pertaining to 3-pins surface mount devices. Using Digikey, I went through the 3-pins devices’ datasheet and collected the 3 parameters for each available package. such parameters are Length, width and height.

Here are the result of my little research.

From the above graphs, the largest package is SC-73 (aka. SOT-223)

Posted in Electronics, PCB | Leave a Comment »

My 4th Year Graduation Project – Autonomous Metal Detector Robot

Posted by Circuit Negma on January 12, 2010


Created By: Hussein Nosair

Posted in Electronics, Microchip PIC | 2 Comments »

MULTILAYER MICROFABRICATION – PART 4 [FINAL]

Posted by Circuit Negma on January 12, 2010


Created By: Hussein Nosair

Resistor, Capacitor and Inductor Fabrication

DSCN2043DSCN2042DSCN2045

DSCN2044DSCN2046DSCN2047

DSCN2048DSCN2049DSCN2051

DSCN2050

Posted in Electronics | Tagged: , | Leave a Comment »

MULTILAYER MICROFABRICATION – PART 3

Posted by Circuit Negma on January 12, 2010


Created By: Hussein Nosair

Looking at the 3rd Layer

DSCN2174DSCN2168DSCN2175

DSCN2176DSCN2177DSCN2179

DSCN2178DSCN2180DSCN2181

DSCN2183DSCN2182DSCN2184

Posted in Electronics | Tagged: , | Leave a Comment »