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.

Help me fix coding for PIC16C745 which will turn on/off a LED light

Status
Not open for further replies.

christina86

Newbie level 5
Joined
Sep 10, 2007
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,374
Dear Friends,

I am using the MPLab 7.2 to write an assembly language using PIC16C745 to turn ON & OFF the Led Light using the push button.

I have successfully burn the Code inside the PIC16C 745 but when i apply the 5V voltage .it failed to turn on.
Here is my code :


list p=16c745 ; list directive to define processor
#include <p16c745.inc> ; processor specific variable definitions

__CONFIG _H4_OSC&_WDT_OFF&_PWRTE_OFF&_CP_OFF




org 0X00000030

Start
bsf STATUS,RP0 ; select bank1
movlw b'00000110' ; Set pins PORTB 1,2 as Input and the rest as "output"
movwf TRISB ;
bcf STATUS, RP0 ; go back to Bank 0


ON
btfsc PORTB,1 ; has S1 been press? (Normally high,goes low when pressed.)
goto ON ; No, go back check again
bsf PORTB,0

OFF
btfsc PORTB,2 ; Has key been press? (Normally high, goes low when pressed.)
goto OFF ; No, check again
bcf PORTB,0

goto Start
end ; directive indicates end of code

Can you help me to check where did i go wrong and how the correct way should be ?
 

Re: Help for 16C745

ur code looks strange...

here is program for ON/OFF of the LED using Interrupts on PIC16F84A, i think you can easily transfer this program to your chip:

Code:
;===================================================== 
; File: RB0Int.ASM 
; Date: April 22, 2006 
; Author: Julio Sanchez 
; Processor: 16F84A 
;===================================================== 
; Description: 
; Program to test interrupt on port RB0 
; A pushbutton switch is connected to port RB0. 
; The pushbutton toggles a LED on port-B, line 7 
; 
; 
;===================================================== 

;========================= 
; setup and configuration 
;========================= 
processor 16f84A 
include <p16f84A.inc> 
__config _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF 

;===================================================== 
; variables in PIC RAM 
;===================================================== 

cblock 0x0d       ; Start of block 
count2               ; ISR counter 
old_w                 ; Context saving 
old_STATUS                 
Delay1          
count1 
endc 


;======================================================== 
; ********** PROGRAM START ********** 
;======================================================== 
org 0                   ; Program start at address 0 
goto main 

;============================= 
; INTERRUPT HANDLER 
;============================= 
org 0x04 
goto IntServ 

;============================= 
; MAIN PROGRAM 
;============================= 
main: 
bsf      STATUS,RP0         ; Select Bank1 
bcf      OPTION_REG,INTEDG   ; Set interrupt on falling edge    
                     ; by clearing INTEDG bit of OPTION_REG    

movlw    b'00000001'         ; PORTB bit 0 
movwf   TRISB            ; is Input, all other bits are Output 

bcf      STATUS,RP0          ; Go back to Bank0    


clrf    PORTB             ; Clear PORTB 
;bsf    PORTB,0          ; set PORTB bit 0 

                     ; SETUP INTERRUPTS 
bcf INTCON,INTF          ; Clear external interrupt flag (INTF = bit 1) 
bsf INTCON,GIE             ; Enable global interrupts (GIE = bit 7) 
bsf INTCON,INTE          ; Enable RB0 interrupt (INTE = bit 4) 

;============================ 
; flash led 
;============================ 
Loop: 

nop 
nop 
nop 
goto   Loop 
;clrf   PORTB 


;======================================================= 
; Interrupt Service Routine 
;======================================================= 

IntServ:               ; First test if source is an RB0 interrupt 
btfss INTCON,INTF          ; INTF flag is RB0 interrupt 
goto notRB0             ; Go if not RB0 origin 

                     ; Save context 
movwf old_w             ; Save w register 
swapf STATUS,w            ; STATUS to w 
movwf old_STATUS          ; Save STATUS 
                     ; Make sure that interrupt occurred on the falling edge 
                     ; of the signal. If not, abort handler 
btfsc PORTB,0             ; Is bit set? 
goto exitISR             ; Go if clear 

;========================= 
; interrupt action 
;========================= 
;clrf   PORTB 
movlw 10                ; Number of repetitions 
movwf count2             ; To counter 
wait:                  ; Check to see that port-B bit 0 is still 0 
                     ; If not, wait until it changes 
btfsc PORTB,0             ; Is bit set? 
goto exitISR             ; Go if bit not 0 
                     ; At this point RB0 bit is clear 
decfsz count2,f          ; Count this iteration 
goto wait                ; Continue if not zero 
                     ; Interrupt action consists of toggling bit 2 of 
                     ; port-B to turn LED on and off 
; ACTION!!!! 

movlw b'10000000'          ; Xoring with a 1-bit produces 
                  ; the complement 
xorwf   PORTB,1             ; Complement bit 2, port-B 

;========================= 
; exit ISR 
;========================= 
exitISR:               ; Restore context 

swapf old_STATUS,w          ; Saved STATUS to w 
swapf old_w,f             ; Swap file register in itself 
swapf old_w,w             ; re-swap back to w 

notRB0:                  ; Reset,interrupt 
bcf INTCON,INTF          ; Clear INTCON bit 1 
retfie 

delay: 
movlw 4 
movwf count1 ; Store value in counter 
repeat: 
decfsz count1,f ; Decrement counter 
goto repeat ; Continue if not 0 
return 

end
 

Re: Help for 16C745

hi,

Thank you so much to post the sample code. Your code only used one switch is it ?
May i know how to schematic be like. May you help me to ponit out where did i go wrong in my code.

Thank you
 

Help for 16C745

it is using active Low logic, take a value of 4.7K for the resistor.
well...ur code is mess, and it doesnt use interrupts, so forget it :D
use interrupts for such things :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top