Led Blinking not working on PORTA (PIC16F877A)

General discussion on mikroC.
Post Reply
Author
Message
User avatar
marko.ziv
mikroElektronika team
Posts: 530
Joined: 06 Dec 2007 10:11
Contact:

Led Blinking not working on PORTA (PIC16F877A)

#1 Post by marko.ziv » 03 Jan 2008 11:35

PIC16F877A has PORTA set to analog by default and led blinking project will not work.

We need to make the following changes in our led blinking code to look like this:

Code: Select all

void main() {
  PORTA = 0;                  // Initialize PORTA
  TRISA = 0;                  // Configure PORTA as output
  ADCON1 = 6;                 // Changes PORTA to digital
  CMCON = 7;                  // Disable analog comparators

  while(1) {
    PORTA =  ~PORTA;          // toggle PORTA
    Delay_ms(1000);           // one second delay
  }
}
This way LEDs from RA0 too RA5 will blink (except RA4)


COL
Posts: 6
Joined: 29 Aug 2012 11:11

Re: Led Blinking not working on PORTA (PIC16F877A)

#3 Post by COL » 30 Aug 2012 07:35

Solved my problem - thank you!

ReinerMSchmidt
Posts: 1
Joined: 26 Sep 2012 15:36

Re: Led Blinking not working on PORTA (PIC16F877A)

#4 Post by ReinerMSchmidt » 26 Sep 2012 15:38

Hey so when you are toggling an LED try to use the XOR operator ( ^= ) also you can check out this tutorial it got me started.

http://roboteurs.com/tutorial-1-micro-c ... nk-an-led/

They also have some cool expansion code

Aryan
Posts: 2
Joined: 25 Oct 2012 16:05

Re: Led Blinking not working on PORTA (PIC16F877A)

#5 Post by Aryan » 25 Oct 2012 19:41

Can you please tell me what are the values of resistor, capacitors and oscillator you used.
If you are not using 8Mhz crystal can you tell me the capacitor values accordingly.
one more thing what is the use of 8 Mhz crystal we use in the circuit and the oscillator which is there in pickit2 burner.

plt34
Posts: 2
Joined: 18 Feb 2014 17:01

Re: Led Blinking not working on PORTA (PIC16F877A)

#6 Post by plt34 » 18 Feb 2014 18:40

i have bad english. i opeden new topic but doesnt seen. please help me answer me. this is my code. but it doesnt complier with microc.
http://i60.tinypic.com/jt29fl.jpg

please send me working c code and hex file.

// Set TEMP_RESOLUTION to the corresponding resolution of your DS18x20 sensor:
// 18S20: 9
// 18B20: 12 (default setting; can be 9,10,11,or 12)
const unsigned short TEMP_RESOLUTION = 12;

const int RES_FACTOR_1[4] = {5000, 2500, 1250, 625};
const unsigned int RES_FACTOR_2[4] = {0x0001, 0x0003, 0x0007, 0x000F};
const unsigned int RES_FACTOR_3[4] = {0x8000, 0xC000, 0xE000, 0xF000};
float alarma;
unsigned temp,temp2,new_temp;
unsigned short j, RES_SHIFT,j2;

void Display_Temperature(unsigned int temp) {
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
unsigned int temp_whole, temp_fraction;
unsigned short i;
char text[8];

// Isolate the fraction and make it a 4-digit decimal integer (for display)
temp_fraction = temp & RES_FACTOR_2[RES_SHIFT - 1];
temp_fraction = temp_fraction * RES_FACTOR_1[RES_SHIFT - 1];
//portc = temp_fraction;
// Handle the whole part of temperature value
temp_whole = temp;

// Is temperature negative?
if ((temp_whole & 0x8000) != 0u) i = 1; // Yes, i = 1
else i = 0; // No, i = 0
// PORTC = i;
// Remove the fractional part
temp_whole >>= RES_SHIFT;

// Correct the sign if necessary
if (i) temp_whole |= RES_FACTOR_3[RES_SHIFT - 1];

//portd = temp_whole;
IntToStr(temp_whole, text); // Convert whole part to string
Lcd_Out(2, 6, text); // Print whole part on LCD
Lcd_Chr_Cp('.'); // Print dot to separate fractional part


IntToStr(temp_fraction, text); // Convert fractional part to string

// Add leading zeroes (we display 4 digits fractional part)
if (temp_fraction < 1000u) Lcd_Chr_Cp('0');
if (temp_fraction < 100u) Lcd_Chr_Cp('0');
if (temp_fraction < 10u) Lcd_Chr_Cp('0');

Lcd_Out_Cp(text); // Print fractional part on LCD

Lcd_Chr_Cp(223); // Print degree character
Lcd_Chr_Cp('C'); // Print 'C' for Centigrades
}//~

void main() {
ADCON1 = 0xFF; // Configure RA5 pin as digital I/O
PORTE = 0xFF;
TRISE = 0x0F; // PORTE is input
PORTB = 0;
TRISB = 0; // PORTB is output
TRISD=0;
PORTD=0;
TRISC=0;
PORTC=0;

// Initialize LCD on PORTB and prepare for output
Lcd_Init();
Lcd_Cmd(_Lcd_CURSOR_OFF);
Lcd_Out(1, 1, "Sicaklik: ");

do { // main loop

Ow_Reset(&PORTE,2); // Onewire reset signal
Ow_Write(&PORTE,2,0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE,2,0x44); // Issue command CONVERT_T
Delay_us(120);

Ow_Reset(&PORTE,2);
Ow_Write(&PORTE,2,0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE,2,0xBE); // Issue command READ_SCRATCHPAD
Delay_ms(400);

j = Ow_Read(&PORTE,2); // Get temperature LSB
j2=j;
temp = Ow_Read(&PORTE,2); // Get temperature MSB
temp2=temp;
temp <<= 8; temp += j; // Form the result
temp2<<=5;
j2>>=3;
new_temp=temp2^j2;
portd=new_temp;
// alarma=39;
alarma=((new_temp*127.5)/255);
if(((alarma>=21.5))) { //YESİL LED AKTIF
PORTC.F0=1;
}

else {
portc.f0=0;}

Display_Temperature(temp); // Format and display result on LCD
Delay_ms(500);

} while (1);

}//~!

User avatar
petar.timotijevic
mikroElektronika team
Posts: 1739
Joined: 19 Feb 2014 13:46
Location: Serbia
Contact:

Re: Led Blinking not working on PORTA (PIC16F877A)

#7 Post by petar.timotijevic » 19 Feb 2014 14:38

Hello,

@plt34

I believe that I answered you on this forum topic:
http://www.mikroe.com/forum/viewtopic.p ... 89#p232689

Best regards,
Peter

Post Reply

Return to “mikroC General”