16f627 timer 1

Status
Not open for further replies.

jeremyhill1989

New Member
Hi guys i am very new to c code language and i am just now writing my first code with the velleman p8048 programming kit and i am trying to program the 16f627. what i want to do is have a timer be started by the input (rao) but i want the timer to leave (portb) on for 20-30 seconds. is this even possible. if it is possible i want it to reset after 30 seconds. please can anyone help i am very new to programming and i need much help. i can get the (portb) light to turn on i just want it to turn on for 30 seconds thanks and here is my code

#include <conio.h>
#define SW1 0x00;

__CONFIG (0x3F61);

void main (void)
{
CMCON = 0x07;
TRISA = 0xFF;
TRISB = 0;
PORTB = 0x01;


while ( 1 )
{
if(RA0 == 1)
PORTB = 0b000001;
else
PORTB = 0b000000;
}
}
 
The tutorials in C in my signature... All you can eat.

Why are you including conio.h ?? You must at least include htc.h...
Code:
 # include<HTC.H>
 
sorry guys this is my new code but i just cannot get it to compile

Code:
#include <htc.h> 
#include <stdio.h> 
#define SW1 0x00;
#define _XTAL_FREQ 4000000;

__CONFIG (0x3F61);

void main (void)
{
CMCON = 0x07;
TRISA = 0xFF;
TRISB = 0;
PORTB = 0x01;
 
 
	while ( 1 )
	{
	 if(RA0 == 1)
        PORTB = 0b000001;
		__delay_ms(9000);
	 else 
		PORTB = 0b000000;	    
	}
}
 
When you compile it you must get errors??? Can we see what they are...
 
this is the error i am getting i think there is a problem with my enviorment


Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC-Lite\9.50\bin\picl.exe" -C -E"test2,c.cce" "test2,c.c" -O"test2,c.obj" -Zg9 -O -ASMLIST -Q -MPLAB -16F627
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC-Lite\9.50\BIN\PICL.EXE" -E"test2.lde" "C:\Users\Jeremy\Desktop\test\test2,c.obj" -M"test2.map" -O"test2.cof" -O"test2.hex" -Q -MPLAB -16F627
BUILD FAILED: Wed Mar 06 14:43:10 2013
 
Here.... There were a couple of errors

First there were two ';' after the definitions _XTAL_FREQ = 4000000 and SW= 00

Also the if statement needs to embody the delay as well with curly brackets {}.


Code:
#include <htc.h> 
#include <stdio.h> 
#define SW1 0x00
#define _XTAL_FREQ 4000000
 
__CONFIG (0x3F61);
 
void main (void)
	{
	CMCON = 0x07;
	TRISA = 0xFF;
	TRISB = 0;
	PORTB = 0x01; 
 
	while ( 1 )
		{
		if(RA0 == 1)
			{
			PORTB = 0b00000001;
			__delay_ms(9000);
			}
	 	else 
			PORTB = 0b00000000;	    
		}
	}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…