Need Help in 7-segment display with I/O

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

Need Help in 7-segment display with I/O

Postby Ryu » Sat Nov 12, 2011 3:05 pm

CODE: SELECT_ALL_CODE
#include <p18f4580.h>
#include <delays.h>

//======================================================

//configuration bit
//===============================================================
#pragma config OSC = HS            //HS Oscillator
#pragma   config FCMEN = OFF         // Fail-Safe Clock Monitor disabled
#pragma   config IESO = OFF         // Oscillator Switchover mode disabled
#pragma   config PWRT = OFF         // PWRT disabled
#pragma   config BOREN = OFF         // Brown-out Reset disabled in hardware and software
#pragma   config WDT = OFF         // WDT disabled (control is placed on the SWDTEN bit)
#pragma   config MCLRE = ON         // MCLR pin enabled; RE3 input pin disabled
#pragma   config PBADEN = OFF         // PORTB<4:0> pins are configured as digital I/O on Reset
//#pragma   config CCP2MX = PORTC         // CCP2 input/output is multiplexed with RC1
#pragma   config LVP = OFF         // Single-Supply ICSP disabled
#pragma   config XINST = OFF         // Extended Instruction Set

//define
//======================================================
#define dis_1 0b00000110
#define dis_2 0b01011011
#define dis_3 0b01001111
#define dis_4 0b01100110
#define dis_5 0b01101101
#define dis_6 0b01111101
#define dis_7 0b00000111
#define dis_8 0b01111111
#define dis_9 0b01100111
#define dis_0 0b00111111

#define seg1_dis PORTD

//main function
//======================================================
void main(void)
{
   unsigned char num = 0;
   unsigned int dis[] = {dis_0,dis_1,dis_2,dis_3,dis_4,dis_5,dis_6,dis_7,dis_8,dis_9};

   TRISD = 0x00;    //set PORTD as output
   PORTD = 0x00;    //clear PORTD

   while(1)
   {
      for (num=0;num<10;num++)
      {
         seg1_dis = dis[num];
         Delay10KTCYx(3000);
      }
   }
}


Hi, does any genius can help me fix the problem ?
this coding is modified from tutorial from cytron website to suite my need. But after i compile and build the simple circuit, the number wouldnt increase.( The circuit is fine with one Common Cathode 7-segment, and resistors) thanks in advance.
Ryu
Newbie
 
Posts: 13
Joined: Sun Aug 14, 2011 10:32 pm

Re: Need Help in 7-segment display with I/O

Postby yonghui » Sat Nov 12, 2011 4:00 pm

i suggest u to change
unsigned int dis[] = {dis_0,dis_1,dis_2,dis_3,dis_4,dis_5,dis_6,dis_7,dis_8,dis_9};

to unsigned char dis[] = {dis_0,dis_1,dis_2,dis_3,dis_4,dis_5,dis_6,dis_7,dis_8,dis_9};

since its only 8 bits.

and change
#define seg1_dis PORTD
to
#define seg1_dis LATD

since the output port of 18F controllers are controlled by different register-> LAT registers.


try see if it correct the thing.


rgds,
yh
thanks&regards,
yh
yonghui
Professional
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Need Help in 7-segment display with I/O

Postby Ryu » Sat Nov 12, 2011 10:29 pm

yonghui WROTE:i suggest u to change
unsigned int dis[] = {dis_0,dis_1,dis_2,dis_3,dis_4,dis_5,dis_6,dis_7,dis_8,dis_9};

to unsigned char dis[] = {dis_0,dis_1,dis_2,dis_3,dis_4,dis_5,dis_6,dis_7,dis_8,dis_9};

since its only 8 bits.

and change
#define seg1_dis PORTD
to
#define seg1_dis LATD

since the output port of 18F controllers are controlled by different register-> LAT registers.


try see if it correct the thing.


rgds,
yh

thank you for reply. I deleted the #define seg1_dis LATD, changed the char, and write PORTD = dis[num] in main function. it worked well oredi. anyway,thank you for giving me tip
Ryu
Newbie
 
Posts: 13
Joined: Sun Aug 14, 2011 10:32 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 2 guests

cron