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.

[SOLVED] need hex file for this code.......

Status
Not open for further replies.
Full Member level 1
Joined
May 1, 2010
Messages
119
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,308
Location
India, Kerala, Moolamattom
Visit site
Activity points
0
Hi All

I need the hex file for an asm code.. This is the code

Code:
// PIC12F675
// 1Hz Time Base Osc.
// Timer1 Module
// 32.768 KHz
unsigned short tick;
void Init ();
void interrupt ()
{
if (PIR1.TMR1IF)
{
TMR1H = 0xE0;
PIR1.TMR1IF = 0;
tick = 1;
}
}
void main ()
{
tick = 0;
//Initialize Ports and Timer1 Module
Init ();
while (1)
{
if (tick)
{
tick = 0;
GPIO = (1 << 2);
}
if (TMR1H > 0xF0)
{
GPIO = 0;
}
}
}
void Init ()


Thank in advance

Regards
 

this file not working
That is because the C code (it is not assembly code) that you posted is incomplete.

The void Init() function at the end of the code you posted is completely empty.

I suspect that you have missed a whole chunk of source code out from the end of your text file.

- - - Updated - - -

By the way....

You can download the C compiler for your code here: https://www.mikroe.com/mikroc/pic/

This is a limited demo version that you can use for free, but will work perfectly for this project.
 
Last edited:

That is because the C code (it is not assembly code) that you posted is incomplete.

The void Init() function at the end of the code you posted is completely empty.

I suspect that you have missed a whole chunk of source code out from the end of your text file.

- - - Updated - - -

By the way....

You can download the C compiler for your code here: https://www.mikroe.com/mikroc/pic/

This is a limited demo version that you can use for free, but will work perfectly for this project.


Sir

Can i get the code for this project?


 

Code attached. Seems to work, but no guarantees.

This is untested amateur code written (especially for you) in a hurry - plenty of scope for improvement.
 

Attachments

  • HMS.rar
    11.9 KB · Views: 82

Timer initialization code is missing in the code in the first post. Maybe

Code C - [expand]
1
Init()

should be

Code C - [expand]
1
InitTimer1()

. It also needs function definition. Mention the Clock freq used for the code in first post. It seems you need a 30 uS interrupt for the 32.768 KHz frequency.
 

Code attached. Seems to work, but no guarantees.

This is untested amateur code written (especially for you) in a hurry - plenty of scope for improvement.


Please Help me....The code is working with only 4 sec and only the last pin. please help me
 
Last edited:

He said no guarantees. You expect help, but you don't do anything yourself. Why don't you download the compiler he suggested and try to modify the code yourself?
Not to be mean or anything, but you're expecting someone else to do your whole work. Show some initiative...

pityu
 

He said no guarantees. You expect help, but you don't do anything yourself. Why don't you download the compiler he suggested and try to modify the code yourself?
Not to be mean or anything, but you're expecting someone else to do your whole work. Show some initiative...

pityu

thanks for your help...But I dont know to write the code and compile....... I pray to all who see this request and help me.....

Regards
 

Well don't you want to learn? Look at post #6 it has a link in it, download the compiler from there, and try to compile the code you gave us. From personal experience i can tell, that you will be getting lot more help on less generic questions.

pityu
 

Well don't you want to learn? Look at post #6 it has a link in it, download the compiler from there, and try to compile the code you gave us. From personal experience i can tell, that you will be getting lot more help on less generic questions.

pityu

Thank you Sir and I download the MPLAB 8.92 and I try to do......Thanks

Regards

- - - Updated - - -

Well don't you want to learn? Look at post #6 it has a link in it, download the compiler from there, and try to compile the code you gave us. From personal experience i can tell, that you will be getting lot more help on less generic questions.

pityu


Sir...

I Get error messages when I compile

This is the error messages

HTML:
Make: The target "C:\Documents and Settings\sethu\Desktop\Timer For Recom\New Folder\HMS.o" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F88 "HMS.asm" /l"HMS.lst" /e"HMS.err"
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 6 : Symbol not previously defined (TRISB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 8 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 10 : Symbol not previously defined (ANSEL)
Warning[202] C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 12 : Argument out of range.  Least significant bits used.
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 13 : Symbol not previously defined (OSCCON)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 17 : Symbol not previously defined (_d4_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 20 : Symbol not previously defined (_d4_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 21 : Symbol not previously defined (STATUS)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 24 : Symbol not previously defined (_d3_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 27 : Symbol not previously defined (_d3_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 28 : Symbol not previously defined (STATUS)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 31 : Symbol not previously defined (_d2_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 34 : Symbol not previously defined (_d2_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 35 : Symbol not previously defined (STATUS)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 38 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 41 : Symbol not previously defined (R11)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 43 : Symbol not previously defined (R12)
Warning[202] C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 44 : Argument out of range.  Least significant bits used.
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 45 : Symbol not previously defined (R13)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 47 : Symbol not previously defined (R13)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 49 : Symbol not previously defined (R12)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 51 : Symbol not previously defined (R11)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 56 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 59 : Symbol not previously defined (R11)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 61 : Symbol not previously defined (R12)
Warning[202] C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 62 : Argument out of range.  Least significant bits used.
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 63 : Symbol not previously defined (R13)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 65 : Symbol not previously defined (R13)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 67 : Symbol not previously defined (R12)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 69 : Symbol not previously defined (R11)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 74 : Symbol not previously defined (_d2_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 79 : Symbol not previously defined (_d2_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 81 : Symbol not previously defined (_d2_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 83 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 86 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 89 : Symbol not previously defined (_d3_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 94 : Symbol not previously defined (_d3_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 96 : Symbol not previously defined (_d3_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 98 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 101 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 104 : Symbol not previously defined (_d4_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 109 : Symbol not previously defined (_d4_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 111 : Symbol not previously defined (_d4_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 113 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 116 : Symbol not previously defined (PORTB)
Error[129]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 124 : Expected (END)
Error[173]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 124 : Source file path exceeds 62 characters (C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM)
Halting build on first failure as requested.
BUILD FAILED: Mon Aug 19 17:29:52 2013
 

Great! Now you'll need to sort these errors out. Start by selecting the correct device, the one you're working with: PIC16F88. You do that by selecting the PIC in the "Select device" window, under the "Configure" menu point.
In the left lower corner you'll see the device that is currently selected. Now you need a compiler, you can get it on microchip website:
https://www.microchip.com/pagehandler/en_us/devtools/mplabxc/
Your controller is 8-bits, so you need XC8 for this. Install it.
Then go to "Project" -> "Select language toolsuite" from the dropdown list select XC8. Press OK, and try to compile again. Let us know how it went.

pityu
 

Thank you Sir and I download the MPLAB 8.92 and I try to do......Thanks

Regards

- - - Updated - - -




Sir...

I Get error messages when I compile

This is the error messages

HTML:
Make: The target "C:\Documents and Settings\sethu\Desktop\Timer For Recom\New Folder\HMS.o" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F88 "HMS.asm" /l"HMS.lst" /e"HMS.err"
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 6 : Symbol not previously defined (TRISB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 8 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 10 : Symbol not previously defined (ANSEL)
Warning[202] C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 12 : Argument out of range.  Least significant bits used.
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 13 : Symbol not previously defined (OSCCON)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 17 : Symbol not previously defined (_d4_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 20 : Symbol not previously defined (_d4_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 21 : Symbol not previously defined (STATUS)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 24 : Symbol not previously defined (_d3_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 27 : Symbol not previously defined (_d3_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 28 : Symbol not previously defined (STATUS)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 31 : Symbol not previously defined (_d2_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 34 : Symbol not previously defined (_d2_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 35 : Symbol not previously defined (STATUS)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 38 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 41 : Symbol not previously defined (R11)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 43 : Symbol not previously defined (R12)
Warning[202] C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 44 : Argument out of range.  Least significant bits used.
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 45 : Symbol not previously defined (R13)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 47 : Symbol not previously defined (R13)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 49 : Symbol not previously defined (R12)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 51 : Symbol not previously defined (R11)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 56 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 59 : Symbol not previously defined (R11)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 61 : Symbol not previously defined (R12)
Warning[202] C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 62 : Argument out of range.  Least significant bits used.
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 63 : Symbol not previously defined (R13)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 65 : Symbol not previously defined (R13)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 67 : Symbol not previously defined (R12)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 69 : Symbol not previously defined (R11)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 74 : Symbol not previously defined (_d2_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 79 : Symbol not previously defined (_d2_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 81 : Symbol not previously defined (_d2_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 83 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 86 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 89 : Symbol not previously defined (_d3_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 94 : Symbol not previously defined (_d3_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 96 : Symbol not previously defined (_d3_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 98 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 101 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 104 : Symbol not previously defined (_d4_count)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 109 : Symbol not previously defined (_d4_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 111 : Symbol not previously defined (_d4_state)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 113 : Symbol not previously defined (PORTB)
Error[113]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 116 : Symbol not previously defined (PORTB)
Error[129]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 124 : Expected (END)
Error[173]   C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM 124 : Source file path exceeds 62 characters (C:\DOCUMENTS AND SETTINGS\SETHU\DESKTOP\TIMER FOR RECOM\HMS.ASM)
Halting build on first failure as requested.
BUILD FAILED: Mon Aug 19 17:29:52 2013


OHHHHHHHH...I can do nothing...I dont know what is going? Please help me please

- - - Updated - - -

Great! Now you'll need to sort these errors out. Start by selecting the correct device, the one you're working with: PIC16F88. You do that by selecting the PIC in the "Select device" window, under the "Configure" menu point.
In the left lower corner you'll see the device that is currently selected. Now you need a compiler, you can get it on microchip website:
https://www.microchip.com/pagehandler/en_us/devtools/mplabxc/
Your controller is 8-bits, so you need XC8 for this. Install it.
Then go to "Project" -> "Select language toolsuite" from the dropdown list select XC8. Press OK, and try to compile again. Let us know how it went.

pityu

You have to try to learn me the programing? I am Appriciate your hard work...Anyway I can done with your help, If you have time..

regards
 

I'm attaching a rar file to you just to get you started. I used hi-tech but aside of some minor changes, it should be compatible! try to run this, and to correct it. I am too, at this moment. :)
 

Attachments

  • edaboard_project.rar
    57.8 KB · Views: 117


The basic idea is to get a flag to toggle every second. Increasing a variable every time this happens will allow you to trigger an event (RB5 goes high) when this variable reaches 60. The next second-interrupt you clear RB5. So you got an impulse when 60 seconds elapsed. You do the same with RB6 RB7, and that's it. RB4 needs to be toggled every second, so there you don't need a counter, it gets toggled every time the if loop is entered.

Code:
#include "htc.h"

__CONFIG(0x0770);

unsigned short tick;
void Init ();

volatile unsigned int counter = 0;
volatile unsigned char second_flag = 0;
unsigned char temp1, temp2, temp3 = 0;

void interrupt isr()
{
if((TMR0IF == 1) && (TMR0IE == 1))
{
if(counter < 10) counter++;
	else
	{
	counter = 0;
	second_flag = 1;
	}
TMR0IF = 0;
TMR0 = 131; // preset for timer register
}
}
void main ()
{
Init();
while(1)
	{
	if(second_flag == 1)
		{
		second_flag = 0; // 1 second elapsed
		PORTB &= 0x1F; // clear from RB4->7 after a second

		RB4 = !RB4;	// light up every second
		temp1++;
		if(temp1 == 60)
		{
		temp1 = 0;
		temp2++;
		RB5 = 1;
		}
		if(temp2 == 6)
		{
		temp2 = 0;
		temp3++;
		RB6 = 1;
		}
		if(temp3 == 2)
		{
		temp3 = 0;
		RB7 = 1;
		}
		}
	}
}

void Init ()
{
OSCCON = 0x72; // internal oscillator used, 8mhz
ANSEL = 0x00; // all digital I/O
TRISB = 0x0F; // RB4-7 outputs, rest inputs
PORTB = 0x00; // clear output latch
INTCON = 0xA0; // enable global and timer0 interrupts
OPTION_REG = 0xC3; // internal clock selected, 1:16 prescaler to timer1
TMR0 = 131; // preset for timer register
}

this works, i just tested it. Here's a hex file too.
 

Attachments

  • hex.rar
    520 bytes · Views: 81
Last edited:

The basic idea is to get a flag to toggle every second. Increasing a variable every time this happens will allow you to trigger an event (RB5 goes high) when this variable reaches 60. The next second-interrupt you clear RB5. So you got an impulse when 60 seconds elapsed. You do the same with RB6 RB7, and that's it. RB4 needs to be toggled every second, so there you don't need a counter, it gets toggled every time the if loop is entered.

Code:
#include "htc.h"

__CONFIG(0x0770);

unsigned short tick;
void Init ();

volatile unsigned int counter = 0;
volatile unsigned char second_flag = 0;
unsigned char temp1, temp2, temp3 = 0;

void interrupt isr()
{
if((TMR0IF == 1) && (TMR0IE == 1))
{
if(counter < 10) counter++;
	else
	{
	counter = 0;
	second_flag = 1;
	}
TMR0IF = 0;
TMR0 = 131; // preset for timer register
}
}
void main ()
{
Init();
while(1)
	{
	if(second_flag == 1)
		{
		second_flag = 0; // 1 second elapsed
		PORTB &= 0x1F; // clear from RB4->7 after a second

		RB4 = !RB4;	// light up every second
		temp1++;
		if(temp1 == 60)
		{
		temp1 = 0;
		temp2++;
		RB5 = 1;
		}
		if(temp2 == 6)
		{
		temp2 = 0;
		temp3++;
		RB6 = 1;
		}
		if(temp3 == 2)
		{
		temp3 = 0;
		RB7 = 1;
		}
		}
	}
}

void Init ()
{
OSCCON = 0x72; // internal oscillator used, 8mhz
ANSEL = 0x00; // all digital I/O
TRISB = 0x0F; // RB4-7 outputs, rest inputs
PORTB = 0x00; // clear output latch
INTCON = 0xA0; // enable global and timer0 interrupts
OPTION_REG = 0xC3; // internal clock selected, 1:16 prescaler to timer1
TMR0 = 131; // preset for timer register
}

this works, i just tested it. Here's a hex file too.



I am really tired..


I just copy and paste this code for the work area of MPLAB.......

and Project>Build All

I get 11 errors

Can you please do it for me? I Beg you..


thanks
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top