How can i use RA6 in PIC18F452

Discussion in 'Embedded Systems and Microcontrollers' started by Error Code, Dec 20, 2009.

  1. Error Code

    Thread Starter New Member

    Dec 20, 2009
    5
    0
    Hello everyone,,

    that's my first post in this forum and am trying to learn how to program a micro-controller and i succeeded till now to learn through the internet but i still have a problem,, am a bit confused on how to use PIN 6 in port A.. i knew that ports A could be digital or analog,, so i chose digital but i want to use the 7 BIT PORTA but i found that RA6 is multiplexed with the OSC,, and am using a 20MHZ OSC,, Does anyone know how to solve that problem ,, or do i have to use an internal OSC to use pin6 ?? if the answer was yes ,, does the PIC16f877 good to be used ??

    well something else,, i read in the datasheet that the pic can write/erase 100,000 times. so is that write or not?? because i bought it from 3 weeks and i erased and burned like 30 or 40 times,, maybe more and now when i try to erase it's not erased and i can't program anymore programs but the chip is working only with the old code. i also checked on another burner and i couldnt erase and checked to set if there was any code protection and my friend how tested it told me that there was a protection although i set to fuze to NOPROTECT but he removed it but couldnt also erase the chip. so how can i solve that issue ?

    thanks in advance :)
     
    Last edited: Dec 20, 2009
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    The only thing you can do is to get a new one.
     
  3. Error Code

    Thread Starter New Member

    Dec 20, 2009
    5
    0
    Thanx for ur reply. i knew that i can use PIN6 only if am using internal clock. but isn't there a solution for my problem to erase the chip?? they said it can erase/write 100,000 so why is it corrupted ??
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Your chip is not corrupted. But somehow the code protection is enabled. This setting is used then you want to protect your code from others. It is like locking the access to your flash memory and throwing away the key. No point of return ;)
     
  5. Error Code

    Thread Starter New Member

    Dec 20, 2009
    5
    0
    isn't setting fuze NOPROTECT means that there is no code protection ?? because that's want i did. and what makes me confused that i tried to erase on my frined's burner - different than mine (I use DIY !!) - and we found that there was code protection, i wonder how !! so we removed it as the programed showed a button to remove Code protection and tried again to erase but we failed. i went to the shop where i bought it from and he told me that he couldn't erase it too and asked me how many times did i burn on it so i told him like 30 times he replied ,, well it just burns 5 or 10 times !!!! i told him that it's written it's about 100000 in the datasheet he told me yes that's written but it doesn't last for all that number of burning !! is he trying to cheat me or what ?? do i buy another one and is the PIC16F877 good for simple codings ??

    another thing to mention,, When i erase using DIY am told that erased is done,, i then do an erase check which shows me that ROM and FUZE not erased although the program told me erased ok !! Right now there is still my last code which i have burned and still working fine. Burning another Hex code results in an error in the ROM because it's not erased i guess.. burning the same HEX code on the chips results in just performing the burning safely without any errors and mistake !! THanks for your help :)
     
  6. eng1ne

    Member

    Dec 4, 2009
    97
    3
    Perhaps post your code...
     
  7. Error Code

    Thread Starter New Member

    Dec 20, 2009
    5
    0
    well am sure it's not the code but anyway i was trying to make a digital clock. Am using CCS compiler. btw this is just for three 7 segment displays because i didnt have the 4th one to complete my code at that time.

    Code ( (Unknown Language)):
    1.  
    2. #include <18f452.h>
    3. #fuses HS,NOWDT,NOPROTECT,NOLVP
    4. #use delay(clock=20000000)
    5.  
    6. unsigned int i,j,k,s,screen = 0;
    7. int b_bin[] = {0x18,0xDE,0x34,0x94,0xD2,0x91,0x11,0xDC,0x10,0x90};
    8. int d_bin[] = {0x84,0xE7,0x4C,0x45,0x27,0x15,0x14,0xC7,0x4,0x5};
    9. int c_bin[] = {0x11,0xD7,0x32,0x92,0xD4,0x98,0x18,0xD3,0x10,0x90};
    10. //long int a_bin[] = {0x77,0x11,0x6B,0x3B,0x1D,0x3E,0x6F,0x13,0x7F,0x3F};
    11.  
    12. int check_state(int num, int range)
    13. {
    14.     if(num < range) { return num = num + 1; }
    15.     else { return 0; }
    16. }
    17.  
    18. void main(void)
    19. {
    20.     delay_ms(1000);
    21.     while(1)
    22.     {
    23.         for(j=0; j<=9; j++)
    24.         {
    25.             output_b(b_bin[j]);
    26.             for(i=0; i<=5; i++)
    27.             {
    28.                 output_d(d_bin[i]);
    29.                 for(k=0; k<=9; k++)
    30.                 {
    31.                     output_c(c_bin[k]);
    32.                     for(s = 0; s<=59; s++)
    33.                     {
    34.                         if(input(PIN_E0))
    35.                         {
    36.                             k--;
    37.                             while(input(PIN_E0)){}
    38.                             output_low(PIN_B4);
    39.                             delay_ms(250);
    40.                             while(1)
    41.                             {
    42.                                 if(input(PIN_E1))
    43.                                 {
    44.                                     while(input(PIN_E1)){}    
    45.                                     delay_ms(250);
    46.                                     if(screen == 0)
    47.                                     {
    48.                                         j = check_state(j,9);
    49.                                         output_b(b_bin[j]);
    50.                                         output_low(PIN_B4);
    51.                                     }
    52.                                     else if(screen == 1)
    53.                                     {
    54.                                         i = check_state(i,5);
    55.                                         output_d(d_bin[i]);
    56.                                         output_low(PIN_D2);
    57.                                     }
    58.                                     else if(screen == 2)
    59.                                     {
    60.                                         k = check_state(k,9);
    61.                                         output_c(c_bin[k]);
    62.                                         output_low(PIN_C4);
    63.                                     }
    64.                                 }
    65.                                 if(input(PIN_E0))
    66.                                 {
    67.                                     while(input(PIN_E0)){}    
    68.                                     delay_ms(250);    
    69.                                     if(screen == 0)
    70.                                     {
    71.                                         output_high(PIN_B4);
    72.                                         output_low(PIN_D2);
    73.                                         screen = 1;
    74.                                     }
    75.                                     else if(screen == 1)
    76.                                     {
    77.                                         output_high(PIN_D2);
    78.                                         output_low(PIN_C4);
    79.                                         screen = 2;
    80.                                     }
    81.                                     else if(screen == 2)
    82.                                     {
    83.                                         output_high(PIN_C4);
    84.                                         screen = 0;
    85.                                         break;
    86.                                     }
    87.                                 }
    88.                             }
    89.                         }
    90.                         output_high(PIN_E2); // Turn ON 2 LEDS
    91.                         delay_ms(500);
    92.                         output_low(PIN_E2);     // Turn OFF 2 LEDS
    93.                         delay_ms(500);
    94.                     }        
    95.                 }
    96.             }
    97.         }
    98.     }
    99. }
    100.  
    101. [/i][/i]
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    What kind of programmer do your friend have, and what kind of software do you use for programming your chip? Perhaps it is some settings in your flash software that you have overlooked.
     
  9. Error Code

    Thread Starter New Member

    Dec 20, 2009
    5
    0
    well i don't remember it's name but it's better than mine. I am using MPLAB and compiling using CCS and i bought i burner which i hate and i was given program called DIY MICROPRO.
     
Loading...