Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to define Ports for PIC16F72 ?

Status
Not open for further replies.

asking

Full Member level 5
Joined
Sep 21, 2010
Messages
279
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Activity points
3,377
Hello,

I have read the Datasheet for PIC16F72 I/O Ports. but m not able to understand if i want to use all ports as I/O Ports what should i do ? There's written by controlling ADCON1 Register we can control function of pins but i m not able to understand the table.


Because i define TRISA, TRISB and TRISC = 0;

but was not successful...so i think there something else required...


Here's the link to download datasheet please help me..https://ww1.microchip.com/downloads/en/devicedoc/39597b.pdf


a little help would be appreciated..
 

ADCON1 is the register that defines PORTA pins for A/D module. For detail see https://www.edaboard.com/blog/1572/ by Tahmid.
TRIS registers are used to define pins direction i.e. 1 for input, 0 for output. e.g. if you want to set pin 2 of Port A as input and rest as output use
TRISA=0x00000100
 
  • Like
Reactions: asking

    asking

    Points: 2
    Helpful Answer Positive Rating
but TRISA = 0; TRISB = 0; TRISC =0; should define all pins as output right ? but its not working with my PIC16F72... i donoo..why...
 

post your code

i want to use for multiplexing 7 Segment 6 Digits...

code for 4 digit for PIC16F628A is:

Code:
unsigned short i, DD0, DD1, DD2, DD3;
unsigned int Count;
//------ Function to Return mask for common anode 7-seg. display
unsigned short mask(unsigned short num) {
 switch (num) {
  case 0 : return 0x3F;
  case 1 : return 0x06;
  case 2 : return 0x5B;
  case 3 : return 0x4F;
  case 4 : return 0x66;
  case 5 : return 0x6D;
  case 6 : return 0x7D;
  case 7 : return 0x07;
  case 8 : return 0x7F;
  case 9 : return 0x6F;
 } //case end
}
void main() {
  CMCON  |= 7;        // Disable Comparators
  TRISB = 0x00; // Set PORTB direction to be output
  PORTB = 0xff;    // Turn OFF LEDs on PORTB
  TRISA = 0b00100000; // RA5 is input only
  Count   =    0;  // Initial Value of Counter

  do {
  DD0 = Count%10;  // Extract Ones Digit
  DD0 = mask(DD0);
  DD1 = (Count/10)%10; // Extract Tens Digit
  DD1 = mask(DD1);
  DD2 = (Count/100)%10; // Extract Hundreds Digit
  DD2 = mask(DD2);
  DD3 = (Count/1000);  // Extract Thousands Digit
  DD3 = mask(DD3);

  for (i = 0; i<=50; i++) {
  
  
      RA3_bit = 1;		//disable RA3
      PORTB = DD0;
      RA0_bit = 0;      // Select Ones Digit
      RA1_bit = 1;
      RA2_bit = 1;
      delay_ms(5);
	  
      RA0_bit = 1;		//disable RA0
      PORTB = DD1;
      RA1_bit = 0;     // Select Tens Digit
      RA2_bit = 1;
      RA3_bit = 1;
      delay_ms(5);
	  
      RA1_bit = 1;		//disable RA1
      PORTB = DD2;
      RA0_bit = 1;
      RA2_bit = 0;     // Select Hundreds Digit
      RA3_bit = 1;
      delay_ms(5);
	  
      RA2_bit = 1;		//disable RA2
      PORTB   = DD3;
      RA0_bit = 1;
      RA1_bit = 1;
      RA3_bit = 0;     // Select Thousands Digit
      delay_ms(5);
      }
      Count = Count + 1 ;
      if (Count > 9999) Count = 0;
  } while(1);          // endless loop
}


what should i define for ports ?
 

If you ar e using amy port as output port then make TRISx = 0x00. If you are using any port as input port make its tris as TRISx = 0xFF. If you are using PORTA and PORTB as output in your code then make their TRIS as TRISA = 0x00; and TRISB = 0x00;
 
  • Like
Reactions: asking

    asking

    Points: 2
    Helpful Answer Positive Rating
If you ar e using amy port as output port then make TRISx = 0x00. If you are using any port as input port make its tris as TRISx = 0xFF. If you are using PORTA and PORTB as output in your code then make their TRIS as TRISA = 0x00; and TRISB = 0x00;

ok....thanks for information...

- - - Updated - - -

can i use 11.0592 MHZ crystal ? in datasheet its written 20MHZ... 20MHZ is maximum or compulsory i have to use 20 MHZ with PIC16F72 ?
 

i HAVE TRIED LED BLINKING PROGRAM BUT LED IS JUST ON ITS NOT OSCILLATING...I MEAN NO EFFECT OF DELAY_MS(100) OR DELAY_MS(1000) I HAVE CONNECTED 11.0592mHZ CRYSTAL WHICH WAS AVAILABLE AT THE MOMENT AND SELECTED HS OSCIALLATOR...WHEN I SELECT XT OSCIALLATOR IN MIKROC ITS NOT STARTING LED..SO USED HS CRYSTAL AND BURN THE PROGRAM ON CHIP...BUT NOT WORKING...ANY IDEA ? WHAT COULD BE WRONG ?

MY CODE
Code:
void main()                      //MAIN;
{
 //ADCON1 = 0b00000000;
 TRISC = 0;                   //SET PORTB TO BE OUTPUT;
 PORTC = 0x00;                   //TURN OFF LEDs ON PORTB;
 while(1){                       //INFINITE LOOP;
          PORTC = ~PORTC;        //INVERT STATE ON PORTB;
          Delay_ms(100);        //WAIT 1S;
         }
          }
 

Your code of 7 seg seem to be OK. So your strategy to LED blinking to confirm that you are able to program correctly is a good way.

a. 20 MHz in datasheet is the upper limit of crystal. You can use crystal of any value even in KHz. So 11.0592MHz should work.
b. You will need to enter your crystal value in the edit Project - Oscilator frequency (MHz)
c. Since your crystal has greater value than 4mhz you will need to select HS in the Oscilator property.
d. The delay 100ms is too small to be easily judge by naked eyes, so increase the delay. For testing I would recommend to use 500ms or above.
e. Just to confirm that you are able to program correctly, try PORTC=0x0F; so one LED at high side should ON when an LED at low side is OFF and vice versa.
 

Thanks its working now..... :) i think 11.0592 will work for now :)

- - - Updated - - -

Actually MCLR pin was open and it was creating humming in the circuit i made it high and everything works fine....actually there is no option to disbale MCLR pin in 16F72 so i made it high by providing +5V and its working fine now.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top