hi,
Do you have the full assembler code that you could post.?
cblock 0x20
Delay1 ; Assign an address to label Delay1
Delay2
endc
Main:
clrf LATB
clrf WREG
clrf TRISB
Loop:
movlw b'11111111'
movwf LATB
call Delay
movlw b'00001111'
movwf LATB
call Delay
goto Loop
Delay:
;movwf Delay2 ;
DelayLoop:
decfsz Delay1,f ; Waste time.
goto DelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz Delay2,f ; The outer loop takes and additional 3 instructions per lap * 256 loops
goto DelayLoop ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
; call it a two-tenths of a second.
return
__config _CONFIG1H, _INTIO2_OSC_1H
__config _CONFIG2L, _PWRT_ON_2L
__config _CONFIG2H, _WDT_OFF_2H
__config _CONFIG3H, _MCLRE_OFF_3H
__config _CONFIG4L, _LVP_OFF_4L
CONFIG OSC = INTIO2, PWRT = ON, WDT = OFF, MCLRE = OFF, LVP = OFF
movlw B'01111111' ; Set all analog ports to digital only (both porta & portb)
movwf ADCON1
Are you using external or internal oscillator?
Oh, I'm using an internal oscillator, as I've given this "CONFIG OSC = INTIO2" before the main program loop.
As bananasiong says, be sure to kick the osc speed up from the very, very slow default clock rate. Default is 31kHz. That caught me out when I was starting with the chip. Things that I wrote assuming 8MHz ran so slowly that I thought my program wasn't working.bananasiong said:If you're using internal oscillator, then you'll have to select the oscillation frequency via OSCCON register, IRCF2:IRCF0. See page 17 of the datasheet for detail.
I was just giving examples
If you're using internal oscillator, then you'll have to select the oscillation frequency via OSCCON register, IRCF2:IRCF0. See page 17 of the datasheet for detail.
bit 7 IDLEN: Idle Enable bits
1 = Idle mode enabled; CPU core is not clocked in power managed modes
0 = Run mode enabled; CPU core is clocked in Run modes, but not Sleep mode
bit 6-4 IRCF2:IRCF0: Internal Oscillator Frequency Select bits
111 = 8 MHz (8 MHz source drives clock directly)
110 = 4 MHz
101 = 2 MHz
100 = 1 MHz
011 = 500 kHz
010 = 250 kHz
001 = 125 kHz
000 = 31 kHz (INTRC source drives clock directly)
bit 3 OSTS: Oscillator Start-up Time-out Status bit
1 = Oscillator Start-up Timer time-out has expired; primary oscillator is running
0 = Oscillator Start-up Timer time-out is running; primary oscillator is not ready
bit 2 IOFS: INTOSC Frequency Stable bit
1 = INTOSC frequency is stable
0 = INTOSC frequency is not stable
bit 1-0 SCS1:SCS0: System Clock Select bits
1x = Internal oscillator block (RC modes)
01 = Timer1 oscillator (Secondary modes)
00 = Primary oscillator (Sleep and PRI_IDLE modes)
Note 1: Depends on state of the IESO bit in Configuration
Hmm.. don't you know, all the registers are 8-bit register. From the datasheet, each bit of OSCCON are:
so for the frequency selection, say 8MHz, you just have to set bit 6 to bit 4 (or IRCF2:IRCF0) to 111, which can be made like this:
movlw 0x70 ; or b'01110000'
movwf OSCCON
Just take your time, it's good for learning ASM, IMO (I'm not trying to start programming language war)
Some other bits are read only, it won't affect anything for read only bits.
Not torture at all.And worse, my next sem's course isn't pertaining PIC - it's the 68HC11. it could be a torture since, 68HC11 is all totally different.
Not torture at all.Motorola (Freescale) CPU's are really nice to program. You'll just have to get used to having more (and better) commands available (the HC's are CISC, not RISC), and of course learn a different architecture and memory map.
That's because, though they're kinda comfy once you get used to them, PICs are freaky strange compared to "normal" CPUs. By learning PIC first, you learned "bad" habits. The PIC way of doing things works great for what they do, but it's quite different from other CPUs (PIC is Harvard arch - virtually no (user accessible) stack - severely limited addressing modes - etc.). IMHO, most programmers would be better off starting out programming a PC or something else before learning the PIC way and thinking it's the norm.It seems lots of the university/college use 68HC11, I don't like it after getting myself into PIC.
It seems lots of the university/college use 68HC11, I don't like it after getting myself into PIC.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?