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.

How to start PIC16F676 ...??

Status
Not open for further replies.
As i said i have changed it value to have more delay!!
please tell what does this .2 significance is that decimal no??

hi,
Look at my Post #33 for the original 0.5Second delay times... .2 is decimal '2'
 
OK, now my latest code which are working fine in oshon....

LIST p=16F676 ;tell assembler what chip we are using
include "P16F676.inc" ;include the defaults for the chip
__config 0x3D14 ;sets the configuration settings (oscillator type etc.)

errorlevel -302, -207

CounterA equ 0x20
CounterB equ 0x21
CounterC equ 0x22
CounterD equ 0x23

; HERE SET TO INTERNAL OSCILLATOR 4MHZ
ORG 0
GOTO INIT

INIT
bcf STATUS,RP0
clrf PORTA
MOVLW 0x05
MOVWF CMCON

BSF STATUS,RP0
clrf ANSEL ; disable ADC

movlw 0x0c
MOVWF TRISA ; porta as inp

clrf TRISC ; portc as out
BCF STATUS,RP0

START
call delay
movlw 0xff
movwf PORTC
call delay
clrf PORTC
GOTO START

;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
delay: movlw D'3'
movwf CounterC
movlw D'138'
movwf CounterB
movlw D'85'
movwf CounterA
loop decfsz CounterA,1
goto loop
decfsz CounterB,1
goto loop
decfsz CounterC,1
goto loop
retlw 0

end
 
hi Ritesh,
Its important to note that while the Delay periods are counting the PIC is 'tied up' doing just that.

If you want to experiment, consider using the PIC's internal counters to create Interrupts for these delays, it will leave the PIC free to do other tasks.
 
Hi again,

After running LED program successfully i want to make a analog to digital program..please guide me how to do this??
 
Select a pic... You'll need a CCP module (PWM output) and an ADC input...

The smallest of these is the 8 pin pic12f1822 / 40 You can set up the 10 bit ADC to supply a 10 bit PWM signal. so input on pin 7 and output on pin 5.

You can do this very easy in Oshonsoft (I know you use this)


Oh sorry....... Not in Oshonsoft .... chip not supported. on of the pics will be though.
 
Last edited:
Sorry, but you don't require an ADC - you can easily read a variable resistor on a standard pin, check my joystick tutorial!.

In many ways it's BETTER than an ADC for reading a pot.


Ah... We used to do that for PC joysticks..... Simple AtoD but wasn't particularly linear.


Ritesh.. That chip hasn't got a PWM module so you'll have to make a software one.
 
Last edited:
I did it yesterday...

Code:
#include<htc.h>
#define _XTAL_FREQ  4000000
__CONFIG(0x31C4);


int OnPulse = 128, OffPulse = 128;
char TOG = 0;

void interrupt ISR(void)
	{
	TOG = ~TOG;
	if(TOG)
		{
		TMR0 = OnPulse;
		RC0 = 1;
		}
	else
		{
		TMR0 = OffPulse;
		RC0 = 0;
		}	
	T0IF = 0;
	}

int ADC_Read()
	{
	ADCON0 = 1;
	__delay_ms(40);
	GO = 1;
	while(GO);
	return ADRESH;
	}

void main()
	{
	int pulse;
	TRISC = 0;
	TRISA = 255;
	CMCON = 7;
	TMR0 = OnPulse;
	ADCON0 = 0x0;
	ADCON1 = 0x50;
	ANSEL = 0x1;
	OPTION_REG = 0;
	T0IE = 1;
	GIE = 1;
	while(1)
		{
		pulse = ADC_Read();
		OnPulse = pulse;
		OffPulse = 255 - OnPulse;		
		}

	}

8bit PWM at 2khz
 
Status
Not open for further replies.

Latest threads

Back
Top