Napsal: 31 kvě 2012, 00:39
Vše, co potřebujete vědět o elektronice :-)
http://elektrobastlirna.cz/
Kód: Vybrat vše
#include "global.h"
unsigned long DisplVal;
/* ==========================================================================
diplay init
*/
void displ_init (void) {
DISPLC_TRIS &= ~DISPLC_MASK;
DISPLC_PORT |= DISPLC_MASK;
DISPLA_TRIS &= ~DISPLA_MASK;
DISPLA_PORT |= DISPLA_MASK;
}
/* ==========================================================================
diplay refresh
*/
void displ_refresh (void) {
unsigned char x;
unsigned long s;
x = DisplVal / 10000000UL;
if(x > 9) {
DisplVal = 0;
x = 0;
}
displ_write(x, 8, 0);
s = DisplVal - (unsigned long)x * 10000000UL;
x = s / 1000000UL;
displ_write(x, 7, 0);
s = DisplVal - (unsigned long)x * 1000000UL;
x = s / 100000UL;
displ_write(x, 6, 0);
s = DisplVal - (unsigned long)x * 100000UL;
x = s / 10000UL;
displ_write(x, 5, 0);
s = DisplVal - (unsigned long)x * 10000UL;
x = s / 1000UL;
displ_write(x, 4, 1);
s = DisplVal - (unsigned long)x * 1000UL;
x = s / 100UL;
displ_write(x, 3, 0);
s = DisplVal - (unsigned long)x * 100UL;
x = s / 10UL;
displ_write(x, 2, 0);
s = DisplVal - (unsigned long)x * 10UL;
x = s / 1UL;
displ_write(x, 1, 0);
}
/* ==========================================================================
diplay write
*/
void displ_write (unsigned char value, unsigned char disp, unsigned char dp) {
DISPLC_PORT |= DISPLC_MASK;
switch (value) {
case 0:
DISPLC_PORT = ~DIS0;
break;
case 1:
DISPLC_PORT = ~DIS1;
break;
case 2:
DISPLC_PORT = ~DIS2;
break;
case 3:
DISPLC_PORT = ~DIS3;
break;
case 4:
DISPLC_PORT = ~DIS4;
break;
case 5:
DISPLC_PORT = ~DIS5;
break;
case 6:
DISPLC_PORT = ~DIS6;
break;
case 7:
DISPLC_PORT = ~DIS7;
break;
case 8:
DISPLC_PORT = ~DIS8;
break;
case 9:
DISPLC_PORT = ~DIS9;
break;
}
switch (disp) {
case 1:
if(dp) DISPLC_PORT &= ~DISDP;
DISPLA1_PORT &= ~DISPLA1_MASK;
delay_dip(50);
DISPLA1_PORT |= DISPLA1_MASK;
break;
case 2:
if(dp) DISPLC_PORT &= ~DISDP;
DISPLA2_PORT &= ~DISPLA2_MASK;
delay_dip(50);
DISPLA2_PORT |= DISPLA2_MASK;
break;
case 3:
if(dp) DISPLC_PORT &= ~DISDP;
DISPLA3_PORT &= ~DISPLA3_MASK;
delay_dip(50);
DISPLA3_PORT |= DISPLA3_MASK;
break;
case 4:
if(dp) DISPLC_PORT &= ~DISDP;
DISPLA4_PORT &= ~DISPLA4_MASK;
delay_dip(50);
DISPLA4_PORT |= DISPLA4_MASK;
break;
case 5:
if(dp) DISPLC_PORT &= ~DISDP;
DISPLA5_PORT &= ~DISPLA5_MASK;
delay_dip(50);
DISPLA5_PORT |= DISPLA5_MASK;
break;
case 6:
if(dp) DISPLC_PORT &= ~DISDP;
DISPLA6_PORT &= ~DISPLA6_MASK;
delay_dip(50);
DISPLA6_PORT |= DISPLA6_MASK;
break;
case 7:
if(dp) DISPLC_PORT &= ~DISDP;
DISPLA7_PORT &= ~DISPLA7_MASK;
delay_dip(50);
DISPLA7_PORT |= DISPLA7_MASK;
break;
case 8:
if(dp) DISPLC_PORT &= ~DISDP;
DISPLA8_PORT &= ~DISPLA8_MASK;
delay_dip(50);
DISPLA8_PORT |= DISPLA8_MASK;
break;
}
}
/* ==========================================================================
delay
*/
void delay_dip (volatile unsigned int value) {
while(value--);
}
Kód: Vybrat vše
#ifndef displH
#define displH
extern unsigned long DisplVal;
/* CONSTANT */
#define DISPLC_TRIS TRISB
#define DISPLC_PORT PORTB
#define DISPLC_MASK 0xFF
#define DISPLA_TRIS TRISA
#define DISPLA_PORT PORTA
#define DISPLA_MASK 0xC3
#define DISPLA1_PORT PORTA
#define DISPLA1_MASK 0xC3
#define DISPLA2_PORT PORTA
#define DISPLA2_MASK 0xC2
#define DISPLA3_PORT PORTA
#define DISPLA3_MASK 0xC1
#define DISPLA4_PORT PORTA
#define DISPLA4_MASK 0xC0
#define DISPLA5_PORT PORTA
#define DISPLA5_MASK 0x83
#define DISPLA6_PORT PORTA
#define DISPLA6_MASK 0x82
#define DISPLA7_PORT PORTA
#define DISPLA7_MASK 0x81
#define DISPLA8_PORT PORTA
#define DISPLA8_MASK 0x80
#define DISPLCA_PORT PORTB
#define DISPLCA_MASK 0x40
#define DISPLCB_PORT PORTB
#define DISPLCB_MASK 0x80
#define DISPLCC_PORT PORTB
#define DISPLCC_MASK 0x02
#define DISPLCD_PORT PORTB
#define DISPLCD_MASK 0x04
#define DISPLCE_PORT PORTB
#define DISPLCE_MASK 0x08
#define DISPLCF_PORT PORTB
#define DISPLCF_MASK 0x20
#define DISPLCG_PORT PORTB
#define DISPLCG_MASK 0x10
#define TLACL_PORT PORTA /* CLEAR button */
#define TLACL_MASK 0x20
#define TLAHL_PORT PORTA /* HOLD button */
#define TLAHL_MASK 0x10
#define DIS0 0xFA
#define DIS1 0x82
#define DIS2 0xB9
#define DIS3 0xAB
#define DIS4 0xC3
#define DIS5 0x6B
#define DIS6 0x7B
#define DIS7 0xA2
#define DIS8 0xFB
#define DIS9 0xEB
#define DISDP 0x04
// FUNCTION
void displ_init (void);
void displ_refresh (void);
void displ_write (unsigned char value, unsigned char disp, unsigned char dp);
void delay_dip (volatile unsigned int value);
#endif
Kód: Vybrat vše
void displ_write(unsigned char value, unsigned char disp, unsigned char dp)
{
static unsigned char dis[10] =
{~DIS0, ~DIS1, ~DIS2, ~DIS3, ~DIS4,
~DIS5, ~DIS6, ~DIS7, ~DIS8, ~DIS9};
DISPLC_PORT |= DISPLC_MASK;
DISPLC_PORT = dis[value];
.
.
.
}
Kód: Vybrat vše
if(dp) DISPLC_PORT &= ~DISDP;
Kód: Vybrat vše
DISPLC_PORT &= dis[value];