PORTA RA0. Help Needed. thank

Discussion in 'Programmer's Corner' started by Ralf, Mar 25, 2009.

  1. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    i using PIC18f24k20 Microchip

    i going to send a number intro that RA0
    may i know how to write the code?

    i using MPLAB C compiler.

    thank for the help..
     
  2. dig1

    Member

    Jul 31, 2008
    18
    0
    if you mean a bit, that's possible i don't know about a number that's a whole set of bits together.... if you are wanting to populate the all the signals on portA, just movlw (number) then movwf PORTA should do...there are other ways to do it too but this most probably is the easiest.. if you just want to change the number then that's a whole different story... (this is based on my knowledge of doing stuff on the PIC16866) so it might be different for your version
     
  3. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    In C, PORTA=1 will set RA0 to 1, if TRISA is 0, with comparators and ADC turned off for that port.

    Is that the processor that comes on the 44 pin PIC Demo board?
     
  4. dig1

    Member

    Jul 31, 2008
    18
    0
    boy i don't mean to hijack the OPs thread, but PORTA=1 will set RA0 to 1 or RA0 through RA5 to 1? i ask this because i am pretty new to PICs
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    00000001b = 0x01 = Rx0
    11111111b = 0xFF = All of PORTx
     
  6. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    thank guy for the reply..

    thatoneguy: i using PIC18f24k20 microchip.. is not the demo board that 44 pin chip. i guess i cannot send number to port A because it only read 1 and 0.. i have another question that is about ADC..

    i know that ADRESH this register is to store the ADC result. if i wanna to convert the result to 3 7-segment, how do i do it??

    probably i wish to know is the result in ADRESH i get is binary , Hex or decimal ?

    thank guy once again for helping me so much
     
  7. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Here is ADC Code with Engrish comments that I found on my drive:
    This writes to 7 segment, characters are defined in TABLE for which digits are lit.


    Code ( (Unknown Language)):
    1.  
    2. [FONT=Arial][SIZE=2][COLOR=#cccccc]1: [/COLOR]#include[SIZE=+1][COLOR=BLUE]<[/COLOR][/SIZE]pic[SIZE=+1][COLOR=BLUE][B].[/B][/COLOR][/SIZE]h[SIZE=+1][COLOR=BLUE]>[/COLOR][/SIZE]              [COLOR=GREEN][I]//include MCU head file
    3. [COLOR=#eeeeee] 2: [/COLOR][/I][/COLOR] __CONFIG[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][COLOR=PINK]0x1832[/COLOR][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]        
    4. [COLOR=#eeeeee] 3: [/COLOR][COLOR=GREEN][I]//THE configure of MCU,watchdog OFF,electrify delay OPEN,power down check OFF,
    5. [COLOR=#eeeeee] 4: [/COLOR][/I][/COLOR][COLOR=GREEN][I]//LOW power programme OFF,encrypt,4M crystal HS surge.
    6. [COLOR=#cccccc] 5: [/COLOR][/I][/COLOR] [COLOR=RED][B]const[/B][/COLOR] [COLOR=RED][B]char[/B][/COLOR] TABLE[SIZE=+1][COLOR=BLUE][B][[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B]][/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B]{[/B][/COLOR][/SIZE]0xc0[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE]0xf9[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE]0xa4[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE]0xb0[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE][COLOR=PINK]0x99[/COLOR][SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE]0x92[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE][COLOR=PINK]0X82[/COLOR][SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE]0XF8[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE][COLOR=PINK]0X80[/COLOR][SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE]0X90[SIZE=+1][COLOR=BLUE][B]}[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    7. [COLOR=#eeeeee] 6: [/COLOR] [COLOR=GREEN][I]//define the table of constant 0-9
    8. [COLOR=#eeeeee] 7: [/COLOR][/I][/COLOR] [COLOR=RED][B]void[/B][/COLOR]  DELAY[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]              [COLOR=GREEN][I]//delay function declare
    9. [COLOR=#eeeeee] 8: [/COLOR][/I][/COLOR] [COLOR=RED][B]void[/B][/COLOR]  init[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]               [COLOR=GREEN][I]//I/O PORT initialize function declare
    10. [COLOR=#eeeeee] 9: [/COLOR][/I][/COLOR] [COLOR=RED][B]void[/B][/COLOR]  display[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][COLOR=RED][B]int[/B][/COLOR] x[SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]       [COLOR=GREEN][I]//display function declare
    11. [COLOR=#cccccc]10: [/COLOR][/I][/COLOR][COLOR=GREEN][I]//------------------------------------------------
    12. [COLOR=#eeeeee]11: [/COLOR][/I][/COLOR]  [COLOR=GREEN][I]//main program
    13. [COLOR=#eeeeee]12: [/COLOR][/I][/COLOR] [COLOR=RED][B]void[/B][/COLOR]  main[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE]              
    14. [COLOR=#eeeeee]13: [/COLOR] [SIZE=+1][COLOR=BLUE][B]{[/B][/COLOR][/SIZE]
    15. [COLOR=#eeeeee]14: [/COLOR]   [COLOR=RED][B]int[/B][/COLOR] result[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][COLOR=PINK]0x00[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]         [COLOR=GREEN][I]//define convert result register              
    16. [COLOR=#cccccc]15: [/COLOR][/I][/COLOR]   [COLOR=RED][B]while[/B][/COLOR][SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][COLOR=BROWN]1[/COLOR][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE]                 [COLOR=GREEN][I]//dead circle                                  
    17. [COLOR=#eeeeee]16: [/COLOR][/I][/COLOR]   [SIZE=+1][COLOR=BLUE][B]{[/B][/COLOR][/SIZE]                                                                      
    18. [COLOR=#eeeeee]17: [/COLOR]   [COLOR=RED][B]int[/B][/COLOR] i[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                   [COLOR=GREEN][I]//define the times of circle control          
    19. [COLOR=#eeeeee]18: [/COLOR][/I][/COLOR]   result[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][COLOR=PINK]0x00[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]             [COLOR=GREEN][I]//clear the convert result                    
    20. [COLOR=#eeeeee]19: [/COLOR][/I][/COLOR]   [COLOR=RED][B]for[/B][/COLOR][SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE]i[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][COLOR=BROWN]5[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]i[SIZE=+1][COLOR=BLUE]>[/COLOR][/SIZE][COLOR=BROWN]0[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]i[SIZE=+1][COLOR=BLUE][SIZE=+1][COLOR=BLUE]-[/COLOR][/SIZE][SIZE=+1][COLOR=BLUE]-[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE]         [COLOR=GREEN][I]//get the average of five convert results      
    21. [COLOR=#cccccc]20: [/COLOR][/I][/COLOR]     [SIZE=+1][COLOR=BLUE][B]{[/B][/COLOR][/SIZE]                                                                    
    22. [COLOR=#eeeeee]21: [/COLOR]      init[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]               [COLOR=GREEN][I]//call initialize function                    
    23. [COLOR=#eeeeee]22: [/COLOR][/I][/COLOR]      ADGO[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][COLOR=PINK]0X1[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]             [COLOR=GREEN][I]//start convert                                
    24. [COLOR=#eeeeee]23: [/COLOR][/I][/COLOR]      [COLOR=RED][B]while[/B][/COLOR][SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE]ADGO[SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]          [COLOR=GREEN][I]//wait for finish convert                      
    25. [COLOR=#eeeeee]24: [/COLOR][/I][/COLOR]      result[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]result[SIZE=+1][COLOR=BLUE]+[/COLOR][/SIZE]ADRESL[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE] [COLOR=GREEN][I]//accumulative total convert results          
    26. [COLOR=#cccccc]25: [/COLOR][/I][/COLOR]      [SIZE=+1][COLOR=BLUE][B]}[/B][/COLOR][/SIZE]                                                                    
    27. [COLOR=#eeeeee]26: [/COLOR]      result[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]result[SIZE=+1][COLOR=BLUE]/[/COLOR][/SIZE][COLOR=BROWN]5[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]      [COLOR=GREEN][I]//get the average of five convert results      
    28. [COLOR=#eeeeee]27: [/COLOR][/I][/COLOR]     display[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE]result[SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]       [COLOR=GREEN][I]//call display function                        
    29. [COLOR=#eeeeee]28: [/COLOR][/I][/COLOR]   [SIZE=+1][COLOR=BLUE][B]}[/B][/COLOR][/SIZE]
    30. [COLOR=#eeeeee]29: [/COLOR]  [SIZE=+1][COLOR=BLUE][B]}[/B][/COLOR][/SIZE]
    31. [COLOR=#cccccc]30: [/COLOR][COLOR=GREEN][I]//-----------------------------------------------
    32. [COLOR=#eeeeee]31: [/COLOR][/I][/COLOR] [COLOR=GREEN][I]//initialize function
    33. [COLOR=#eeeeee]32: [/COLOR][/I][/COLOR]
    34. [COLOR=#eeeeee]33: [/COLOR] [COLOR=RED][B]void[/B][/COLOR]  init[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE]              
    35. [COLOR=#eeeeee]34: [/COLOR]  [SIZE=+1][COLOR=BLUE][B]{[/B][/COLOR][/SIZE]
    36. [COLOR=#cccccc]35: [/COLOR]   PORTA[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]0XFF[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]              
    37. [COLOR=#eeeeee]36: [/COLOR]   PORTD[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]0XFF[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]               [COLOR=GREEN][I]//close all display                                          
    38. [COLOR=#eeeeee]37: [/COLOR][/I][/COLOR]   TRISA[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][COLOR=PINK]0X1[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                [COLOR=GREEN][I]//set RA0 INPUT,the others OUTPUT                            
    39. [COLOR=#eeeeee]38: [/COLOR][/I][/COLOR]   TRISD[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][COLOR=PINK]0X00[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]               [COLOR=GREEN][I]//set D PORT all OUTPUT                                      
    40. [COLOR=#eeeeee]39: [/COLOR][/I][/COLOR]   ADCON1[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]0X8E[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]              [COLOR=GREEN][I]//set RA0 simulate INPUT,the others general I/O              
    41. [COLOR=#cccccc]40: [/COLOR][/I][/COLOR]   ADCON0[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][COLOR=PINK]0X41[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]              [COLOR=GREEN][I]//system clock Fosc/8,select RA0 routeway,allow ADC work      
    42. [COLOR=#eeeeee]41: [/COLOR][/I][/COLOR]   DELAY[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                  [COLOR=GREEN][I]//ensure sampling delay                                      
    43. [COLOR=#eeeeee]42: [/COLOR][/I][/COLOR]   [SIZE=+1][COLOR=BLUE][B]}[/B][/COLOR][/SIZE]
    44. [COLOR=#eeeeee]43: [/COLOR][COLOR=GREEN][I]//-----------------------------------------------
    45. [COLOR=#eeeeee]44: [/COLOR][/I][/COLOR][COLOR=GREEN][I]//display function            
    46. [/I][/COLOR][SIZE=+1][COLOR=BLUE][/COLOR][/SIZE]
    47.  
    48. [/SIZE][/FONT]


    CONTINUED IN NEXT POST
    [SIZE=+1][/SIZE]Code coloriaztion by http://www.chamisplace.com/colorizer/cc.asp
     
  8. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718

    ADC - 7 Segment - continued.....

    Code ( (Unknown Language)):
    1.  
    2. [FONT=Arial][SIZE=2][COLOR=GREEN][I][COLOR=#cccccc]45: [/COLOR][/I][/COLOR] [COLOR=RED][B]void[/B][/COLOR] display[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][COLOR=RED][B]int[/B][/COLOR] x[SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE]          
    3. [COLOR=#eeeeee]46: [/COLOR]   [SIZE=+1][COLOR=BLUE][B]{[/B][/COLOR][/SIZE]
    4. [COLOR=#eeeeee]47: [/COLOR]     [COLOR=RED][B]int[/B][/COLOR]  bai[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE]shi[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE]ge[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE]temp[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]   [COLOR=GREEN][I]//define four temporary variable                
    5. [COLOR=#eeeeee]48: [/COLOR][/I][/COLOR]     temp[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]x[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                 [COLOR=GREEN][I]//temporary keep AD convert result              
    6. [COLOR=#eeeeee]49: [/COLOR][/I][/COLOR]     bai[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]temp[SIZE=+1][COLOR=BLUE]/[/COLOR][/SIZE][COLOR=PINK]0x64[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]          [COLOR=GREEN][I]//get display hundred bit                        
    7. [COLOR=#cccccc]50: [/COLOR][/I][/COLOR]     shi[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE]temp[SIZE=+1][COLOR=BLUE]%[/COLOR][/SIZE][COLOR=PINK]0x64[/COLOR][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE]/[/COLOR][/SIZE]0xa[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]    [COLOR=GREEN][I]//get display ten bit                            
    8. [COLOR=#eeeeee]51: [/COLOR][/I][/COLOR]     ge[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE]temp[SIZE=+1][COLOR=BLUE]%[/COLOR][/SIZE][COLOR=PINK]0x64[/COLOR][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE]%[/COLOR][/SIZE]0xa[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]     [COLOR=GREEN][I]//get display Entries bit                        
    9. [COLOR=#eeeeee]52: [/COLOR][/I][/COLOR]     PORTD[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]TABLE[SIZE=+1][COLOR=BLUE][B][[/B][/COLOR][/SIZE]bai[SIZE=+1][COLOR=BLUE][B]][/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]       [COLOR=GREEN][I]//get the display hundred bit code from table    
    10. [COLOR=#eeeeee]53: [/COLOR][/I][/COLOR]     PORTA[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][COLOR=PINK]0x37[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]             [COLOR=GREEN][I]//RA3 OUTPUT low,light hundred bit display      
    11. [COLOR=#eeeeee]54: [/COLOR][/I][/COLOR]     DELAY[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                [COLOR=GREEN][I]//delay some time,ensure display brightness      
    12. [COLOR=#cccccc]55: [/COLOR][/I][/COLOR]     PORTD[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]TABLE[SIZE=+1][COLOR=BLUE][B][[/B][/COLOR][/SIZE]shi[SIZE=+1][COLOR=BLUE][B]][/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]       [COLOR=GREEN][I]//get the display ten bit code from table        
    13. [COLOR=#eeeeee]56: [/COLOR][/I][/COLOR]     PORTA[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]0x2F[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]             [COLOR=GREEN][I]//RA4 OUTPUT low,light ten bit display          
    14. [COLOR=#eeeeee]57: [/COLOR][/I][/COLOR]     DELAY[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                [COLOR=GREEN][I]//delay some time,ensure display brightness      
    15. [COLOR=#eeeeee]58: [/COLOR][/I][/COLOR]     PORTD[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]TABLE[SIZE=+1][COLOR=BLUE][B][[/B][/COLOR][/SIZE]ge[SIZE=+1][COLOR=BLUE][B]][/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]        [COLOR=GREEN][I]//get the display Entries bit code from table    
    16. [COLOR=#eeeeee]59: [/COLOR][/I][/COLOR]     PORTA[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE]0x1F[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]             [COLOR=GREEN][I]//RA5 OUTPUT low,light Entries bit display      
    17. [COLOR=#cccccc]60: [/COLOR][/I][/COLOR]     DELAY[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                [COLOR=GREEN][I]//delay some time,ensure display brightness      
    18. [COLOR=#eeeeee]61: [/COLOR][/I][/COLOR]   [SIZE=+1][COLOR=BLUE][B]}[/B][/COLOR][/SIZE]
    19. [COLOR=#eeeeee]62: [/COLOR]
    20. [COLOR=#eeeeee]63: [/COLOR][COLOR=GREEN][I]//----------------------------------------------
    21. [COLOR=#eeeeee]64: [/COLOR][/I][/COLOR][COLOR=GREEN][I]//delay program
    22. [COLOR=#cccccc]65: [/COLOR][/I][/COLOR][COLOR=RED][B]void[/B][/COLOR]  DELAY[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE]              [COLOR=GREEN][I]//delay program            
    23. [COLOR=#eeeeee]66: [/COLOR][/I][/COLOR]    [SIZE=+1][COLOR=BLUE][B]{[/B][/COLOR][/SIZE]                                                
    24. [COLOR=#eeeeee]67: [/COLOR]     [COLOR=RED][B]int[/B][/COLOR] i[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                 [COLOR=GREEN][I]//define integer variable
    25. [COLOR=#eeeeee]68: [/COLOR][/I][/COLOR]     [COLOR=RED][B]for[/B][/COLOR][SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE]i[SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE][COLOR=PINK]0x100[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]i[SIZE=+1][COLOR=BLUE][SIZE=+1][COLOR=BLUE]-[/COLOR][/SIZE][SIZE=+1][COLOR=BLUE]-[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]     [COLOR=GREEN][I]//delay                  
    26. [COLOR=#eeeeee]69: [/COLOR][/I][/COLOR]    [SIZE=+1][COLOR=BLUE][B]}
    27. [/B][/COLOR][/SIZE][/SIZE][/FONT]
    Code coloriaztion by http://www.chamisplace.com/colorizer/cc.asp
     
  9. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    thank thatoneguy.

    i now trying it.. thank alot...
     
  10. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    thank thatoneguy.

    i copy my code here.. i think there and i got a few question to ask.

    #include <p18f24k20.h>
    #include <adc.h>

    #pragma config FOSC = XT //Oscillator Setting
    #pragma config WDTEN = OFF //Turn off WatchDog


    void ADC_Init (void)
    {
    ADCON0 = 0x01; // select channel 0 (AN0) to read the potentionmeter voltage and thurn on ADC
    ADCON1 = 0x00; // sets bits VCFG1 and VCFG0 in ADCON1 so the ADC coltage reference is VSS to VDD
    ADCON2 = 0x01; // A/D conversion clock select bits to Fosc/8
    }

    void ADC_Convert (void)
    {
    int temp;
    ADCON0bits.GO_DONE = 1; //Start Conversion
    while (ADCON0bits.GO_DONE == 1); // wait for it to complete
    ADRESH = temp ; // return high byte of result
    }

    void main (void) //Function
    {

    TRISA = 0x01; //PORT A RA0 is Input and the rest output
    TRISB = 0; //PORT
    TRISC = 0;



    }

    may i know is there any wrong with my program?
     
  11. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    PORTA[SIZE=+1]=TABLE[SIZE=+1][[/SIZE]bai[SIZE=+1]][/SIZE][SIZE=+1];[/SIZE] //get the display hundred bit code from table
    [/SIZE] PORTB[SIZE=+1]=TABLE[SIZE=+1][[/SIZE]shi[SIZE=+1]][/SIZE][SIZE=+1];[/SIZE] //get the display hundred bit code from table
    [/SIZE] PORTC[SIZE=+1]=TABLE[SIZE=+1][[/SIZE]ge[SIZE=+1]][/SIZE][SIZE=+1];[/SIZE] //get the display hundred bit code from table [/SIZE]

    thatoneguy i got something to ask u.. if i change it like this will my display go to port A B and C?
    bcoz my Port A , B and C each have 1 7-segment display
     
  12. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    No, the LEDs are multiplexed so the data is on the same bus, and the common anode/cathode is switched to make that segment light up. They are scanned hundreds of times per second, so it looks persistent.

    Easier to program, takes fewer uC pins, and is the standard for 7 segment displays, especially when they are over 2 digits.
     
  13. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    cool.. i about to off work now.. tomorrow will u be on? just in case i have a few question.. and hope u can reply.. thank alot thatoneguy.

    thank everyone for helping me..
     
  14. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    void DELAY() //delay program
    {
    int i; //define integer variable
    for(i=0x100;i--;); //delay
    }

    may i know if i want a 1 sec delay.. wad number should i use?
     
  15. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    There should be a delay_ms(), delay_cycle() or similar function in Microchip C18, the above is written to be "translate to assembly" friendly.
     
  16. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    when i build my program i have a error on this line..

    void display(int x)

    the error is syntax error

    why?? need help again.. thank
     
  17. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    just wanted to know. my program is almost done and i wish to add on an interrupt for my program. just wish to know how the interrupt really work? how should i program it?
     
  18. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    The error with the display function most likely has something to do with the following.

    You need a function prototype for each function, stating what values are passed to the function and how, along with what type of value is returned from the function (void = nothing in this case). This make things easier/faster for the compiler to find errors in fewer passes, as well as an index of functions for the program author to refer to.

    at the top of the code, you will see:

    void display (int x);

    then the rest of the code

    Then the actual function:
    void display (int x)
    {

    ..
    }

    Some compilers do not like a named parameter in the prototype, so removing the variable name 'x' at the top of the program, if that is where the flag is coming up, should fix it.
    try:
    void display (int);


    Using the C Library delay_ms() functions, the headache of calculating how many cycles to 'waste' with various clock speeds is removed, as long as the #pragma clock 16000000 is in the program (for a 16Mhz processsor).


    As far as using seperate 7 segment displays on seperate ports, that could be done, but the multiplexing code would need to be removed. If you already have it wired one way, it can be made to work, the overall concern is total power dissipation of the package. With 3 displays, nearly all I/O ports would be tied up for the display only.

    The 18F Series allows for 25mA source/sink per pin, but total package dissipation is a max of 200mA or 1W, whichever is lower. If you don't mind using 21 pins for display, removing the mplex software (what the delay is for), and the total draw for all LED's display "8" is under 200mA, you can use them on seperate ports.

    Speaking of I/O pins and power on them, is there a reason you are using an external clock for this application? The internal oscillator runs at 16Mhz, and up to 64Mhz with a bit of PLL programming (shown in datasheet).

    Lastly, what did you want to implement interrupts to do?

    Once it is working that far, compiles, and can display, we will tune up the ADC and Interrrupts. I have a 18f45k20, and an order of 18f26k20 inbound, so i'll be able to give the exact code and diagram if all else fails. :) I normally use BoostC from http://www.sourceboost.com, The license for non-commercial use is Extremely Affordable, and it is 'free' for smaller programs. License also includes their NovoRTOS operating system to help with multitasking. Quite a bargain for when your C18 optimizer expires.

    *I am not affiliated with sourceboost at all, just an extremely happy customer of theirs*

    --ETA: Sorry for the late reply! I didn't notice this thread got updated until just now...
     
    Last edited: Apr 2, 2009
  19. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    thank thatoneguy.. u help me alot.. :)

    hope i did not waste your time.. u really help me alot for my project. :)

    currently i using switch case for my program because i found out that my IC chip PORTA not all pin is connected to LED A,

    current the problem i facing is writing switch case and as i post here b4 that i using 3 LED to display my result and i found out that:

    LED A using PORT of RA1,RA2,RA3,RA4,RA5,RB6 and RB7 (Using PORTA and B)
    LED B using PORT of RB0,RB1,RB2,RB3,RB4,RB5 and RC7 (Using PORTB and C)
    LED C using PORT of RC0,RC1,RC2,RC3,RC4,RC5 and RC6 (Only PORTC)

    as can see that i using 2 port for 1 LED that why i planning to using switch case.

    thatoneguy can i ask u that for 18F24k20 if i wanna to set porta RA1 as a 0 what command should i write? i know is something LATAbits.___ = 0
    i dont know what to put at the place i underline.

    once again.. really thank for the help.. i super appreciate it.. thank bro

    PS: if anything dont really understand please let me know.. i try to phrase it other way.. thank!
     
  20. Ralf

    Thread Starter Active Member

    Mar 16, 2009
    31
    0
    i think i got it how to write a switch case but now is how to write that LATAbits.___ = 0 this part. once i got it i think i can finish my switch case stuff..

    thank for the help.. :)
     
Loading...