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.

PWM signal with pic16f877a on RC1 and RC2

Status
Not open for further replies.

jean12

Advanced Member level 2
Joined
Aug 27, 2013
Messages
529
Helped
5
Reputation
12
Reaction score
6
Trophy points
18
Activity points
5,497
Hello there,here are the codes I used the techniques of EEPROM reading and writing for generating a PWM signal unfortunately I am not able to get the signal on RC1 and RC2 of the PIC ,can some one help me to think on this?

Thanks.




PHP:
;*****************************************************************************
;
;*****************************************************************************
                                                                           


	LIST      p=16F877A            ; Définition de processeur
	#include <P16F877A.inc>        ; fichier include

	ERRORLEVEL -302	;Warning registre de destination
	ERRORLEVEL -207	;Warning Label after column 1

	__CONFIG   _CP_OFF & _DEBUG_ON & _WRT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC 


;*****************************************************************************
;                               ASSIGNATIONS SYSTEME                         *
;*****************************************************************************

OPTIONVAL	EQU	B'11000000'
			; RBPU     b7 : 1= Résistance rappel +5V hors service
		;				B6 : Rising edge Trig RB0
;for EEPROM 
	;EEADR	EQU		0X10D;BANK2
	;EEDATA	EQU		0X10C;BANK2
	;EECON1	EQU		0X18C;BANK3
	;EECON2	EQU		0X07;for EECON1
;	EEPGD	EQU		0X01;for EECON1
	;RD		EQU		0X00;for EECON1
	;WREN	EQU		0X02;for EECON1
;*****************************************************************************
;                           ASSIGNATIONS PROGRAMME                           *
;*****************************************************************************

	MAXDUTY		EQU D'115'			;Duty cycle maximum (BUCK)
	ADRESSE     EQU   H'F00F' 

;*****************************************************************************
;                        VARIABLES BANQUE 0                                  *
;*****************************************************************************


locales UDATA 0x20	;Début de la zone (0x20 à 0x6F)
	
	tmp1	RES 1 ;declaration des variables à utiliser pour la routine delay de temporisation
	tmp2 	RES 1 ;declaration des variables à utiliser pour la routine delay de temporisation
    

;*****************************************************************************
;                      VARIABLES ZONE COMMUNE                                *
;*****************************************************************************

; Zone de 16 bytes
; ----------------

globales UDATA_SHR ; Début de la zone (0x71 à 0x7F)
					;Adresse 70H est utilisée par le système
	w_temp RES 1
	status_temp RES 1
	locall RES 1
	COMPTEUR RES 1
	FLAG	RES 1
	CPT		RES 1
;*****************************************************************************
;				Définitions				     *
;*****************************************************************************

	;#DEFINE PWMOUT		PORTC,2 ;definir le port de sortie du PWM
	;#DEFINE LED    PORTB,4
;*********************************************************************
;                             MACRO                                  *
;*********************************************************************
;definition des Bank pour les differentes registres
BANK0 macro                ;bits RP0,RP1 sont à 00 respectivement             
		bcf STATUS,RP0
		bcf STATUS,RP1
	endm
BANK1 macro                ;bits RP0,RP1 sont à 01 respectivement 
		bsf STATUS,RP0
		bcf STATUS,RP1
	endm
BANK2 macro                 ;bits RP0,RP1 sont à 10 respectivement 
		bsf STATUS,RP1
		bcf STATUS,RP0
	endm
BANK3 macro                  ;bits RP0,RP1 sont à 11 respectivement 
		bsf STATUS,RP0
		bsf STATUS,RP1
	endm                     ;fin du definition des Bank pour les differentes registres

	;ORG 0X2100
		;	addressing data to the EEPROM
  ORG 0x2100    
   DE D'236'
   DE D'236'
   DE D'235'
   DE D'235'
   DE D'235'
   DE D'234'
   DE D'233'
   DE D'233'
   
		
;*****************************************************************************
;                      DEMARRAGE SUR RESET                                   *
;*****************************************************************************

	ORG 0x00 		;Adresse de départ après reset
	nop 			;Pour ICD2
 	goto START		;Initialiser

; ////////////////////////////////////////////////////////////////////////////

;                         I N T E R R U P T I O N S

; ////////////////////////////////////////////////////////////////////////////

;*****************************************************************************
;                     ROUTINE INTERRUPTION                                   *
;*****************************************************************************

			;sauvegarder registres	
			;---------------------
	ORG 0x004				;Adresse des interruptions
	movwf w_temp  			;Sauver registre W
	swapf STATUS,w			;Swap status avec résultat dans w
	movwf status_temp		;Sauver status swappé sans modification

restorereg
	swapf status_temp,w		;Swap ancien status, résultat dans w
	movwf STATUS			;Restaurer status
	swapf w_temp,f			;Inversion L et H de l'ancien W
                       		;sans modifier Z du STATUS
	swapf w_temp,w  		;Réinversion de L et H dans W
							;W restauré sans modifier status
	retfie  				;Return from interrupt



; ////////////////////////////////////////////////////////////////////////////
;                           P R O G R A M M E
; ////////////////////////////////////////////////////////////////////////////

;a completer après

START
        
		BANK1
		BCF TRISC,2	
		BCF TRISC,1
		BANK0
		BCF PORTC,2
	    BCF PORTC,1
		
      ;Reading EEPROM Value one by one

		MOVLW d'249'
		BANK1
		MOVWF PR2
		MOVLW 0X0C
		BANK0
		MOVWF CCP1CON
		;MOVLW d'1'
		;MOVWF T2CON
		
		BANK2
		CLRF EEADR
		CLRF EEADRH
		CLRF EEDATA
		movlw 0x21
		movwf EEADRH
		movlw 1
		MOVWF EEADR
read  	
		BANK3
		BCF EECON1,EEPGD
		BSF EECON1,RD
		nop
		BANK2
		MOVF EEDATA,W
		GOTO PWM ;my modification		
		INCF  EEADR,F
		GOTO read
		;RETURN
PWM 
		BANK0
		BSF T2CON,TMR2ON
		CLRF CCPR1L
		MOVWF CCPR1L
		return		
		
		
	end
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top