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.

[PIC] PIC 18f4520 TMR0L , need setting for OPTION_REG

Status
Not open for further replies.

Asanka Lakmal Morawaka

Newbie level 4
Joined
Nov 7, 2014
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
32
Hello,

Please help me OPTION_REG gives error(see the attached image), this is mikroc example for 16F877A, but I trying to use for 18F4520

thankyou

HTML:
 

Attachments

  • Untitled.png
    Untitled.png
    79.3 KB · Views: 156

There is something else.
Check whether you had opened the correct project and most important pic16 is selected.

I had tested it in my mikroc Compiler OPTION_REG works.

Otherwise please upload your code here, i will solve this problem.
 
This is the code;
Code:
#include "Display_utils.h"

unsigned short shifter, portd_index;
unsigned int   digit, number;
unsigned short portd_array[4];

void interrupt() {
  PORTA = 0;                             // Turn off all 7seg displays
  PORTD = portd_array[portd_index];      // bring appropriate value to PORTD
  PORTA = shifter;                       // turn on appropriate 7seg. display

  // move shifter to next digit
  shifter <<= 1;
  if (shifter > 8u)
    shifter = 1;

  // increment portd_index
  portd_index++ ;
  if (portd_index > 3u)
    portd_index = 0;                     // turn on 1st, turn off 2nd 7seg.

  TMR0L   =   0;                          // reset TIMER0 value
  INTCON = 0x20;                         // Clear T0IF
}//~

void main() {
  //ANSEL       =    0;                    // Set AN pins to Digital I/O
  //ANSELH      =    0;
  OPTION_REG  = 0x80;                    // Timer0 settings
  digit       =    0;
  portd_index =    0;
  shifter     =    1;
  TMR0L        =    0;
  INTCON      = 0xA0;                    // Enable GIE, T0IE
  PORTA       =    0;
  TRISA       =    0;                    // Set PORTA as output
  PORTD       =    0;
  TRISD       =    0;                    // Set PORTD as output

  number          =   6789;              // some initial value
  do {
    digit = number / 1000u ;             // extract thousands digit
    portd_array[3] = mask(digit);        // and store it to PORTD array
    digit = (number / 100u) % 10u;       // extract hundreds digit
    portd_array[2] = mask(digit);        // and store it to PORTD array
    digit = (number / 10u) % 10u;        // extract tens digit
    portd_array[1] = mask(digit);        // and store it to PORTD array
    digit = number % 10u;                // extract ones digit
    portd_array[0] = mask(digit);        // and store it to PORTD array

    Delay_ms(1000);                      // one second delay

    number++ ;                           // increment number
    if (number > 9999u)
      number = 0;

  } while(1);                            // endless loop
}

displaying number on four 7-segment display (common
cathode), in multiplex mode. All 7-segment displays are connected to PORTD
(RD0..RD7, segment A to RD0, segment B to RD1, etc) with refresh via pins
RA0..RA3 on PORTA. Number is on for 1 second.
 

I had a similar problem with my pic18f452. Later i found out that the option register doesnt even exist on my chip. So i guess you better search whether you have option register in your chip or its in the name some other register as horace1 mentioned.
All pic microcontrollers are not code compatible. Minor changes have to be done. The datasheet gives you everything.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top