Youth deterent!

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Post Reply
jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Youth deterent!

Post by jgu1 »

Hi!

I am trying to create/convert the "youth deterent" from Bert v Dam´s book from FC5 to FC7. But when I compile the program I get "error code 1"
and it have something to do with tmr0, I use the C command: tmr0=0x195;

It work in FC5 but not in FC7. Can anybody tell me what I am doing wrong please?

Br Jorgen
Attachments
Youth1.fcfx
(8.38 KiB) Downloaded 193 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Youth deterent!

Post by Benj »

Hi Jorgen,

In v7 you need to capitalise the register name to work with the xc8 compiler.

Code: Select all

TMR0 = 0x195;
Also your value looks wrong, should this be 195 instead of 0x195? 0x195 is a 12-bit value and the TMR0 regiser is an 8-bit register.

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Youth deterent!

Post by jgu1 »

Hi Ben!

Thank´s again for REALLY fast reply. And it work. :D

Br Jorgen

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Youth deterent!

Post by medelec35 »

Hi Jorgen,
Deterrent will not work on hardware unless you change Clock source select within Interrupt properties from:

Code: Select all

Transition on T0CKI pin 
to

Code: Select all

Internal clock.
Otherwise intrerrupt will be waiting for a change on T0CKI pin.

Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Youth deterent!

Post by jgu1 »

Hi Martin!

No I see now when you spotted this, of course, thank´s. I have to test it later on hardware. I could not understand why I not was able to compile.

My goal is, to create random frequencies from16Khz to 40Khz in approx. 2-3 kHz step. I have to measure how high the freq is if I set TIM0 to:
TMR0 = 0x254;

Thank´s Martin for spotting.

Br Jorgen

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Youth deterent!

Post by medelec35 »

Your welcome.
jgu1 wrote:TMR0 = 0x254;
You have got that wrong!

Values are:
Decimal:

Code: Select all

TMR0 = 0; 
to

Code: Select all

TMR0 = 255;
or
Hex:

Code: Select all

TMR0 = 0x0; 
to

Code: Select all

TMR0 = 0xFF;
Although in practice you would not go too near the highest value of dec 255 or hex 0xFF

Martin
Martin

Post Reply