Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16f676 to 16f72 conversion

Status
Not open for further replies.

sahu

Member
i'm trying volt meter code conversion 16f676 to 16f72 step by step . use CCS C
16f676 code as
Code:
#include <16F676.h>
#device adc=10 
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR
#use delay (clock=4000000) // 4MHz clock

#rom  0x3ff={0x3444}

#byte PORTA = 0x05
#byte PORTC = 0x07
#byte TRISA = 0x85
#byte TRISC = 0x87

#define SPORTA PORTA
#define SPORTC PORTC

#define  TICKS_BETWEEN_INTERRUPTS      5000 //5000
#define  INTERRUPT_OVERHEAD            35
#define  TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))

const char SegCode[11] = {0x40,0x57,0x22,0x06,0x15,0x0C,0x08,0x56,0x00,0x04,0xFF};
	//                  0    1    2    3    4    5    6    7    8    9
const char Column[3]   = {0x02,0x01,0x04};
static char Segment[3] = {0x7f,0x7f,0x7f};	
static unsigned char ColCount=0x00;

void CPU_SETUP(void);
void Display(void);
void HTO7S(unsigned int32 Num);

byte i;
unsigned int32 result;

#INT_TIMER1
void Timer1(void)
{	
	set_timer1(TMR1RESET);
	Display();	
}	

void main()
{		
	unsigned char i;
	
	CPU_SETUP();
	
	while(true)
	{			
		result=0;
		for (i=0;i<20;i++)
		{
			set_adc_channel(3); 
			delay_ms(1); 
			result=result+read_adc();
		}
			//result = 0x3fe;									
	 	HTO7S(result/20);	
		delay_ms(200);		    
	}
	
}

void CPU_SETUP()
{
 	
   setup_comparator(NC_NC_NC_NC);	// not use comparator module
   setup_adc_ports( sAN3 | VSS_VDD); 
   setup_adc(ADC_CLOCK_DIV_64);
   TRISA=0b00011000;
   PORTA=0x27;
   TRISC=0b00000000;
   PORTC=0x37;
   
   
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   set_timer1(TMR1RESET);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER1);   
}

//-------------------------------------
// Display routine
//-------------------------------------
void Display()
{
	PORTA = 0b00100111;	  // off all digits column and Segment G
	PORTC = 0b00111111;   // off segment a-f	
	delay_cycles(2);
	

	if (ColCount>=3) 
	ColCount=0;
    	
	SPORTC = Segment[ColCount];
	SPORTA = ((Segment[ColCount] & 0b01000000)>>1) | (Column[ColCount]^0x07);
	ColCount++;				
}	

//--------------------------------------
// Convet HEX 2 byte to 7-Segment code
//--------------------------------------
void HTO7S(unsigned int32 Num)
{

	unsigned int32 res;

	
	Segment[0]=SegCode[30*Num/10230];
	if (Segment[0]==0x40) 
	Segment[0]=0xFF;
	
	res = 30*Num%10230;
	Segment[1]=SegCode[10*res/10230];
	res=10*res%10230;
	Segment[2]=SegCode[10*res/10230];
}

1st of all trying understand
7seg. aregment
676 as
const char SegCode[11] = {0x40,0x57,0x22,0x06,0x15,0x0C,0x08,0x56,0x00,0x04,0xFF};
// 0 1 2 3 4 5 6 7 8 9
i want 72 as
Code:
	Ues 7 Segment Common Anod

	PORT RB7 = A
	PORT RB6 = B
	PORT RB5 = C
	PORT RB4 = D
	PORT RB3 = E
	PORT RB2 = F
	PORT RB1 = G

	PORT RB0 = Display 1
	PORT RC7 = Display 2
	PORT RC6 = Display 3

***********************************************************************************************
		0= on , 1 = off

         a
	---
       |   |b
     f | g |
        ---
       |   |c
     e |   |
        ---
         d
************************************************************************************************
	______________________________________________________
PORT	|RB7	|RB6	|RB5	|RB4	|RB3	|RB2	|RB1  |
________|_______|_______|_______|_______|_______|_______|_____|
	| A	| B	| C	| D	| E	| F	| G   |
	|_______|_______|_______|_______|_______|_______|_____|
Digit
_______________________________________________________________
  1 =	  1	 0	 0	 1	1	 1	 1	=
_______________________________________________________________
  2 =	  0 	 0	 1	 0	0	 1	 0 	=
_______________________________________________________________
  3 =	  0	 0 	 0	 0	1	 1	 0	=
_______________________________________________________________
  4 =	  1	 0	 0	 1	1	 0 	 0	=
_______________________________________________________________
  5 =	  0	 1 	 0	 0	1	 0	 0	=
_______________________________________________________________
  6 =	  1	 1	 0	 0	0	 0	 0	=
_______________________________________________________________
  7 =	  0	 0	 0	 1	1	 1	 1	=
_______________________________________________________________ 
  8 =	  0	 0 	 0	 0	0	 0	 0	=
_______________________________________________________________
  9 =	  0	 0	 0	 0	1	 0	 0	=
_______________________________________________________________
OFF =	  1	 1	 1	 1	1	 1	 1	=
_______________________________________________________________
but confuse whats right
for exampled digit
1 = 1 0 0 1 1 1 1 = 4F Is right or
1 = 1 0 0 1 1 1 1 = 79 is right
 
but confuse whats right
for exampled digit
1 = 1 0 0 1 1 1 1 = 4F Is right or
1 = 1 0 0 1 1 1 1 = 79 is right

Both are not right..... you are dismissing the LSBit... so 1001111x will be 0x9E hex or 158 decimal
 
Both are not right..... you are dismissing the LSBit... so 1001111x will be 0x9E hex or 158 decimal

Thank u sir for reply 7 guide me .
as per Ur sussation
Code:
	Ues 7 Segment Common Anod

	PORT RB7 = A
	PORT RB6 = B
	PORT RB5 = C
	PORT RB4 = D
	PORT RB3 = E
	PORT RB2 = F
	PORT RB1 = G

	PORT RB0 = Display 1
	PORT RC7 = Display 2
	PORT RC6 = Display 3

***********************************************************************************************
		0= on , 1 = off

         a
	---
       |   |b
     f | g |
        ---
       |   |c
     e |   |
        ---
         d
************************************************************************************************
	______________________________________________________
PORT	|RB7	|RB6	|RB5	|RB4	|RB3	|RB2	|RB1  |
________|_______|_______|_______|_______|_______|_______|_____|
	| A	| B	| C	| D	| E	| F	| G   |
	|_______|_______|_______|_______|_______|_______|_____|
Digit
_______________________________________________________________
  1 =	  1	 0	 0	 1	1	 1	 1	= 9E
_______________________________________________________________
  2 =	  0 	 0	 1	 0	0	 1	 0 	= 24
_______________________________________________________________
  3 =	  0	 0 	 0	 0	1	 1	 0	= C
_______________________________________________________________
  4 =	  1	 0	 0	 1	1	 0 	 0	= 98
_______________________________________________________________
  5 =	  0	 1 	 0	 0	1	 0	 0	= 48
_______________________________________________________________
  6 =	  1	 1	 0	 0	0	 0	 0	= C0
_______________________________________________________________
  7 =	  0	 0	 0	 1	1	 1	 1	= 1E
_______________________________________________________________ 
  8 =	  0	 0 	 0	 0	0	 0	 0	= 0
_______________________________________________________________
  9 =	  0	 0	 0	 0	1	 0	 0	= 8
_______________________________________________________________
OFF =	  1	 1	 1	 1	1	 1	 1	= FF
_______________________________________________________________
now i'm doing right ?
 
how can manege displays ?
( PORT RB0 = Display 1
PORT RC7 = Display 2
PORT RC6 = Display 3 )
 
The best way is to setup a interrupt to update the displays when required..... Nigel's tutorials have a multiplexed 7 segment tutorial...

See the link in my signature.
not understand . in
tutorial 10... Dual seven segment display ( common anode )
my conversion in shown fig.
 

Attachments

  • 676 to 72.GIF
    676 to 72.GIF
    24.5 KB · Views: 1,061
What do you mean "how can manege displays ?"

How many seven segment displays have you got?
my mean how can manege displays with ( PORT RB0 = Display 1
PORT RC7 = Display 2
PORT RC6 = Display 3 ).
for exampled 1 = 1 0 0 1 1 1 1
so pl give example for digit 1 , 2 & 3 management
 
Last edited:
You are using MikroC... I use XC8 or C18.... If I give you an example ( there is one in MY tutorial... 10 same as Nigel's ) but It wont work on your compiler.

Do I get from the title that you have pic16f72 ?
 
You are using MikroC... I use XC8 or C18.... If I give you an example ( there is one in MY tutorial... 10 same as Nigel's ) but It wont work on your compiler.

Do I get from the title that you have pic16f72 ?

i'm using CCS C & PIC 16F72 , not MikroC.
in 1st post is complete code vm for 30 v dc , i want it convert 600 vac & 16f72.
also lurn step by step its function.
 
i'm using CCS C & PIC 16F72 , not MikroC.
in 1st post is complete code vm for 30 v dc , i want it convert 600 vac & 16f72.
also lurn step by step its function.

I'm just changing it to run on my sim... I have converted to Hi tech to see what gives.... Just trying to get the interrupt working..
 
Still can't get the interrupt going..... I really can't see why.... The TMR1IE is set and the GIE is set.... But when the TMR1IF goes high... It doesn't enter the ISR??????

It may be a problem with the sim or the compiler.... I think its the compiler because in the dissasembly the ISR hasn't got a REFIE command or the SWAPF to reinstate the W reg...

Digging deeper...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top