help..my program doesn't work

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

help..my program doesn't work

Postby FakeSheep » Fri Apr 13, 2012 8:55 pm

list p=18f4550
#include P18f4550.INC

DelayD1 equ 0x00
DelayD2 equ 0x01
;--------------------------------------------------
org 0000h
goto Start

org 00020h
Start:
movlb B'00000010' ;FE0H,back select 02H
movlw B'01100010' ;FE8H,62H
movwf OSCCON
movlw B'00000000'
movwf TRISD ;F93H
clrf PORTD ;PORTB,F81H
movlw H'00'
movwf LATD

;------------------------------------------------------
Main:
movlw H'FF'
movwf PORTD
call Delay
movlw H'00'
movwf PORTD
call Delay
goto Main

;--------------------------------------------------------
Delay:
movlw H'FF'
movwf DelayD1
Del1:
movlw H'FF'
movwf DelayD2
Del2:
decfsz DelayD2,1
goto Del2
decfsz DelayD1,1
goto Del1
return
;-------------------------------------------------------
End
;------------------------------------------------------------------------------------------



1. First, the problem is my PIC no response at all.
2. output msg is BUILD SUCCEEDED.
3. this program is only to control LEDs blinking
4. I'm using MPLAP IDE, MPASM Assembler v5.44
5. I used MPLAB SIM to simulated this program
6. The OSCCON i want to set it as 01100010(62H),
but dunno y simulation result is always show that OSCCON is 01100000(60H)
7. This Fcuk-ing shit still doesn't WORK
8. Last, if u guys need any photo or anything else to better understand with my problem, pls feel free to ask, thanks =]
FakeSheep
Novice
 
Posts: 24
Joined: Sun Jul 10, 2011 4:13 pm

Re: help..my program doesn't work

Postby Brian Griffin » Fri Apr 13, 2012 11:46 pm

Have you checked whether you have turned off the ADC and the Comparators/PWM first?
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: help..my program doesn't work

Postby FakeSheep » Sat Apr 14, 2012 12:32 am

as im using pic18f4550
I not really sure how to do it
if to off the Capture/compare/PWM and ADC module
is it should be like this?
movlw H'00'
movwf CCP1CON
movwf ADCON0

i already tried but still can't work..have u try my program? is it working with ur chip?
FakeSheep
Novice
 
Posts: 24
Joined: Sun Jul 10, 2011 4:13 pm

Re: help..my program doesn't work

Postby ABSF » Sat Apr 14, 2012 6:53 am

FakeSheep WROTE:org 00020h
Start:
movlb B'00000010' ;FE0H, select Bank 2
movlw B'01100010' ;FE8H,62H Use internal OSC at 4 MHz
movwf OSCCON
movlw B'00000000'
movwf TRISD ;F93H set all Port D to output
clrf PORTD ;PORTB,F81H
;Your instruction says PORTD but your comment says Port B, where did you connect your LED?
movlw H'00'
movwf LATD


I simulated in Proteus and it worked.
May be you should add a little more looping in your delay subroutine to make the flashing more visible. Running at 4MHz, my rough calculation got that you delay is only 132 mS which is too fast for your eyes. Try this:-

CODE: SELECT_ALL_CODE
;PIC Time Delay = 1.0000020 s with Osc = 4.000000 MHz

counterA  equ 0x02
counterB  equ 0x03
counterC  equ 0x04

   movlw   D'6'
   movwf   CounterC
   movlw   D'24'
   movwf   CounterB
   movlw   D'168'
   movwf   CounterA
loop   decfsz   CounterA,1
   goto   loop
   decfsz   CounterB,1
   goto   loop
   decfsz   CounterC,1
   goto   loop
   return


Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: help..my program doesn't work

Postby FakeSheep » Sat Apr 14, 2012 11:44 am

Yes, i already checked my hardware
But 1 thing is, i tried to set my OSCCON as B'01100010' which is internal OSC with 4Mhz
i simulated it and the result show below:
Image
i cant able to set OSCCON as B'01100010', but only B'01100000'
FakeSheep
Novice
 
Posts: 24
Joined: Sun Jul 10, 2011 4:13 pm

Re: help..my program doesn't work

Postby FakeSheep » Sat Apr 14, 2012 11:48 am

FakeSheep
Novice
 
Posts: 24
Joined: Sun Jul 10, 2011 4:13 pm

Re: help..my program doesn't work

Postby FakeSheep » Sun Apr 15, 2012 9:50 am

Can anyone help me pls?
FakeSheep
Novice
 
Posts: 24
Joined: Sun Jul 10, 2011 4:13 pm

Re: help..my program doesn't work

Postby ABSF » Sun Apr 15, 2012 10:57 am

FakeSheep WROTE:Yes, i already checked my hardware
But 1 thing is, i tried to set my OSCCON as B'01100010' which is internal OSC with 4Mhz

i cant able to set OSCCON as B'01100010', but only B'01100000'


bit 1-0 SCS1:SCS0: System Clock Select bits
1x = Internal oscillator
01 = Timer1 oscillator
00 = Primary oscillator


The primary oscillators include the External Crystal
and Resonator modes, the External Clock modes and
the internal oscillator block. The particular mode is
defined by the FOSC3:FOSC0 Configuration bits. The
details of these modes are covered earlier in this
chapter.


I am not familiar with the MPLAB simulator. But if it set the 1x internal oscillator to 00 Primary Oscillator. The control is passed to Configuration bits CONFIG1H......

4550_config.JPG
CONFIG1H contents


Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: help..my program doesn't work

Postby FakeSheep » Sun Apr 15, 2012 12:14 pm

i still can't work with it...any sample can let me refer?
or suggest me any other assembler or IDE etc?(ASM based pls, I'm suck in C, yet)
bcoz seems like no much body are using MPLAB...
it is quite sad that no much body can help with my problem and i can't even control a LED blinking
i stuck at situation like now for a long time
FakeSheep
Novice
 
Posts: 24
Joined: Sun Jul 10, 2011 4:13 pm

Re: help..my program doesn't work

Postby ABSF » Sun Apr 15, 2012 2:49 pm

What about this program?

CODE: SELECT_ALL_CODE
;connect LED to PortD, Bit 1
#include P18F4550.INC
CONFIG WDT=OFF; disable watchdog timer
CONFIG MCLRE = ON; MCLEAR Pin on
CONFIG DEBUG = ON; Enable Debug Mode
CONFIG LVP = OFF; Low-Voltage programming disabled (necessary for debugging)
CONFIG FOSC = INTOSCIO_EC;Internal oscillator, port function on RA6
 org 0; start code at 0
 CBLOCK 0
Delay1:1
Delay2:1
 ENDC
 ORG 0
;Delay1 res 1 ;reserve 1 byte for the variable Delay1
;Delay2 res 1 ;reserve 1 byte for the variable Delay2
Start:
 CLRF PORTD
 CLRF TRISD
 CLRF Delay1
 CLRF Delay2
MainLoop:
 BTG PORTD,RD1 ;Toggle PORT D PIN 1 (20)
Delay:
 DECFSZ Delay1,1 ;Decrement Delay1 by 1, skip next instruction if Delay1 is 0
 GOTO Delay
 DECFSZ Delay2,1
 GOTO Delay
 GOTO MainLoop
 end


Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 0 guests

cron