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.

Help in PWM

Status
Not open for further replies.
Hi there, Welcome to electro-tech
I'm not using atmega ,never did and also not using C, I;m a PIC guy and use assembly language but, I recently made a code to control brightness of an LED connected at PORTC, pin 0 of 16f690, Let me put the code and that may help you to develop your own........
Code:
 	List p=16f690
	#include<p16f690.inc>
	__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
	ERRORLEVEL-302
;***********************************************************************
	cblock 0x20
		temp
		d1
		d2
		dis
	endc
;************************************************************************
	org 0x0
	goto main
;************************************************************************
main:
portset:
	bsf STATUS,RP0		;all output
	clrf TRISA
	clrf TRISB
	clrf TRISC
	bcf STATUS,RP0
PWMset:
	movlw b'00000001'
	movwf PORTC
	call bright1		;call delay for that much time LED to be bright
	movlw b'00000000'
	movwf PORTC
	call bright2		; call delay for an LED to remain off
	goto PWMset
bright1:
	movlw d'200'		; select on time delay
	movwf d1
delayon:
	decfsz d1
	goto delayon
	return
bright2:
	movlw d'56'			;select off time delay
	movwf d2
delayoff:
	decfsz d2
	goto delayoff
	return
	end
note that total of on and off delay should be 256 for an 8 bit processor.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top