People do not bother to learn and configure a complex hardware, so they move to a fixed and standardized hardware, that effort is eliminated.
its not that people don't bother , its that there are no pbp tools to do it properly.
i will give you an simple example of the problem that demonstrates why i don't bother making anymore "hardware module" code for pbp any longer
if you extrapolate this to include port/pin choices,on chip hardware and complex memory needs its no wonder that no "libraries" exist .
take my tm1637 demo
http://www.picbasic.co.uk/forum/showthread.php?t=23417
the code is small, efficient and feature rich and works wonderfully, usercommand allows it fit seemlessy into pbp as though it was a pbp function.
problem is it only works on enhanced core pic16 devices.
to use it on a older chip like a pic12f683 it needs a bit of work these chips have only got one 8 bit FSR and no BRW opcode
whereas the modern chips have 2 16 bit FSR's and a BRW opcode .
therefore my rjust function can't work on these old chips and the rest of the code needs a bit of a tweak too
the asm portion of the code becomes :-
Code:
SEG_val ;VALID INPUT 0-9 ,A-F, a-f ," " ,-
CHK?RP _TM_TMP
MOVWF _TM_TMP
SUBLW 0x21
btfsc STATUS, C
retlw 0 ;" "
MOVF _TM_TMP,W
SUBLW 0x2f
btfsc STATUS, C
retlw 64 ;"-"
MOVF _TM_TMP,W
MOVLW 0X40
SUBWF _TM_TMP,W
btfsC STATUS, C
GOTO TM_ALPHA
MOVF _TM_TMP,W
ANDLW 0X0F
GOTO TM_LU
TM_ALPHA
ANDLW 0xdf ;ucase
SUBLW 6
btfsS STATUS, C
retlw 0 ;ERROR
MOVLW 0X37
SUBWF _TM_TMP,W
ANDLW 0xdf ;ucase
TM_LU
addwf PCL, F
retlw 0X3F ;0
retlw 6
retlw 0X5B
retlw 0X4F
retlw 0X66
retlw 0X6D
retlw 0X7D
retlw 7
retlw 0X7F
retlw 0X67 ;9
retlw 0X77 ;A
retlw 0X7C ;b
retlw 0X39 ;C
retlw 0X5E ;d
retlw 0X79 ;E
retlw 0X71 ;F
TM_START
_TM_START
CHK?RP TM_OUT_PORT
BSF TM_OUT_PORT,TM_CLK
BSF TM_OUT_PORT,TM_DIO
NOP
BCF TM_OUT_PORT,TM_DIO
NOP
BCF TM_OUT_PORT,TM_CLK
;NOP
RETURN
TM_STOP
_TM_STOP
CHK?RP TM_OUT_PORT
BCF TM_OUT_PORT,TM_CLK
BCF TM_OUT_PORT,TM_DIO
NOP
BSF TM_OUT_PORT,TM_CLK
NOP
BSF TM_OUT_PORT,TM_DIO
;NOP
RETURN
TM_WRITE
_TM_WRITE
MOVLW 8
CHK?RP _TM_BIT
MOVWF _TM_BIT
NXBT
CHK?RP TM_OUT_PORT
BCF TM_OUT_PORT,TM_CLK
CHK?RP _TM_DAT
BTFSS _TM_DAT,0
GOTO TM_0
CHK?RP TM_OUT_PORT
BSF TM_OUT_PORT,TM_DIO
GOTO TM_NB
TM_0
CHK?RP TM_OUT_PORT
BCF TM_OUT_PORT,TM_DIO
TM_NB
CHK?RP _TM_DAT
RRF _TM_DAT,F
CHK?RP TM_OUT_PORT
BSF TM_OUT_PORT,TM_CLK
CHK?RP _TM_BIT
DECFSZ _TM_BIT,F
GOTO NXBT
CHK?RP TM_OUT_PORT
BCF TM_OUT_PORT,TM_CLK
CHK?RP TM_TRIS
BSF TM_TRIS,TM_DIO
CHK?RP TM_IN_PORT
BTFSC TM_IN_PORT,TM_DIO
BSF _TM_NAK,7
CHK?RP TM_OUT_PORT
BSF TM_OUT_PORT,TM_CLK
NOP
NOP
NOP
NOP
BCF TM_OUT_PORT,TM_CLK
CHK?RP TM_TRIS
BCF TM_TRIS ,TM_DIO
BANKSEL 0
RETURN
_TM_INIT
CHK?RP _TM_COLON
CLRF _TM_COLON
CLRF _TM_BRIGHT
CHK?RP TM_TRIS
BCF TM_TRIS ,TM_DIO
BCF TM_TRIS ,TM_CLK
BANKSEL 0
RETURN
_TM_DISP4
CHK?RP _TM_DAT
MOVLW _CMD_AUTO_ADDR
MOVWF _TM_DAT
CLRF _TM_NAK
CALL TM_START
CALL TM_WRITE
CALL TM_STOP
MOVLW _NUM_DIGITS
CHK?RP _TM_DIG
MOVWF _TM_DIG
MOVLW _START_ADDR
CHK?RP _TM_DAT
MOVWF _TM_DAT
CALL TM_START
CALL TM_WRITE
NXDIG
MOVF INDF,W
INCF FSR ,f
CALL SEG_val
CHK?RP _TM_DAT
IORWF _TM_COLON ,W
movwf _TM_DAT
CALL TM_WRITE
CHK?RP _TM_DIG
DECFSZ _TM_DIG,F
GOTO NXDIG
CALL TM_STOP
CHK?RP _TM_BRIGHT
MOVF _TM_BRIGHT ,W
ANDLW 7
IORLW _DISPLAY_ON
CHK?RP _TM_DAT
MOVWF _TM_DAT
CALL TM_START
CALL TM_WRITE
CALL TM_STOP
BANKSEL 0
RETURN
ENDASM
but it still wont work on a pic18 they have no MOVIW, MOVWI OR BRW opcodes.
so it needs a rework for them too. apita .its not easy to cover all the bases . i wrote the code to suit my app
at that time . if i need to use the code on a different chip i don't want to keep reinventing the wheel, a modular approach
is what i'm looking for. pbp simply has no tools to make that process a pleasant one.
to do the same thing in C needs no asm code other than a few NOPs for timing and is fully portable with no changes needed
eg
c source :-
Code:
#include "tm1637.h"
/*pin manager DEFINES :-
TM_DIO ,TM_CLK
*/
char TM_BRIGHT=1,TM_COLON=COLON_OFF ;
void SET_TM_COLON(char d){
if (d)
TM_COLON=COLON_ON;
else
TM_COLON=COLON_OFF;
}
void SET_TM_BRIGHT(char d){
TM_BRIGHT = d&7;
}
void TM_START(){
TM_CLK_LAT=1;
TM_DIO_LAT=1;
asm ("NOP");
TM_DIO_LAT=0;
asm ("NOP");
TM_CLK_LAT=0;
}
void TM_STOP(){
TM_CLK_LAT=0;
TM_DIO_LAT=0;
asm ("NOP");
TM_CLK_LAT=1;
asm ("NOP");
TM_DIO_LAT=1;
}
char TM_WRITE(char dat){
char bit_cnt;
for (bit_cnt=0;bit_cnt<8;bit_cnt++){
TM_CLK_LAT=0;
TM_DIO_LAT=dat&1;
dat>>=1;
TM_CLK_LAT=1;
}
TM_CLK_LAT=0;
TM_DIO_SetDigitalInput();
bit_cnt=TM_DIO_GetValue();
TM_CLK_LAT=1;
#asm
NOP
NOP
NOP
NOP
#endasm
TM_CLK_LAT=1;
TM_DIO_SetDigitalOutput();
return bit_cnt; //NAK IF SET
}
void TM_DISP(char* buff){
char dat,TM_DIG,tmp;
dat=CMD_AUTO_ADDR;
TM_START();
TM_WRITE(dat);
TM_STOP();
dat=START_ADDR;
TM_START();
TM_WRITE(dat);
for(TM_DIG=0;TM_DIG<NUM_DIGITS;TM_DIG++ ){
tmp=buff[TM_DIG];
dat=SEG_VAL(tmp)|TM_COLON;
TM_WRITE(dat);
}
TM_STOP();
dat=(TM_BRIGHT&7)|DISPLAY_ON;
TM_START();
TM_WRITE(dat);
TM_STOP();
}
char SEG_VAL(char dat){
const char seg_data[]={ 0X3F,6,0X5B,0X4F,0X66,0X6D,0X7D,7,0X7F,0X67,0X77,0X7C,0X39,0X5E,0X79,0X71};
if (isdigit(dat))
return seg_data[dat-'0'];
else if (isxdigit(dat))
return seg_data[toupper(dat)-'A'+10];
else if (dat=='-')
return 64;
else
return 0;
}
and the header file :-
Code:
/*
* File: tm1637.h
* Author: rc
*
* Created on January 3, 2018, 4:42 PM
*/
#ifndef TM1637_H
#define TM1637_H
#ifdef __cplusplus
extern "C" {
#endif
#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "mcc_generated_files/mcc.h"
#include "mcc_generated_files/pin_manager.h"
#define CMD_AUTO_ADDR 0x40
#define START_ADDR 0xc0
#define NUM_DIGITS 0x4 //number of 7seg leds
#define COLON_ON 0x80
#define DISPLAY_ON 0x88
#define COLON_OFF 0
void TM_START();
void TM_STOP();
char TM_WRITE(char);
char SEG_VAL(char);
void TM_DISP(char*);
void SET_TM_COLON(char);
void SET_TM_BRIGHT(char);
#ifdef __cplusplus
}
#endif
#endif /* TM1637_H */
and a C example of usage
Code:
#include <xc.h>
#include "mcc_generated_files/mcc.h"
#include "mcc_generated_files/pin_manager.h"
#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "tm1637.h"
#include "hx711.h"
/*pin manager DEFINES :-
TM_DIO ,TM_CLK
HX_OUT,HX_SCH
ZERO_SW
*/
void main(void)
{
short long cnt;
char buffer[5];
SYSTEM_Initialize();
SET_TM_BRIGHT(2);
while ( HX_OUT_GetValue()){} ;
while (1)
{
if(!ZERO_SW_GetValue() ) {
SET_HX_ZERO();
while (!ZERO_SW_GetValue() ) {};
}
cnt = READ_HX711();
cnt >>=5;
SET_TM_COLON(0);
sprintf(buffer,"%4d",cnt);
TM_DISP(buffer);
__delay_ms(500);
}
}
to do the same in pbp code is possible but twice the size and half as fast with less features . and that is for a very simple device
http://www.picbasic.co.uk/forum/show...196#post144196
Bookmarks